Skip to content

Commit 3162fdf

Browse files
authored
Merge pull request #1 from PhoenixEmik/master
Add NetEase Music Onebox
2 parents ed7b72b + c2213ec commit 3162fdf

File tree

3 files changed

+2196
-0
lines changed

3 files changed

+2196
-0
lines changed

lib/onebox/cloudmusic.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Onebox
2+
module Engine
3+
class CloudMusicOnebox
4+
include Engine
5+
include StandardEmbed
6+
include HTML
7+
8+
matches_regexp(/^https?:\/\/music\.163\.com\/#(\/m)?\/song\?id=([\d]+)(&userid=[\d]+)?$/)
9+
10+
def music_id
11+
match = uri.fragment.match(/\/song\?id=([\d]+)/)
12+
return match[1] if match && match[1]
13+
14+
nil
15+
rescue
16+
return nil
17+
end
18+
19+
def to_html
20+
"<iframe frameborder=\"no\" border=\"0\" marginwidth=\"0\" marginheight=\"0\" width=330 height=86 src=\"http://music.163.com/outchain/player?type=2&id=#{music_id}&auto=0&height=66\"></iframe>"
21+
end
22+
23+
def placeholder_html
24+
to_html
25+
end
26+
end
27+
end
28+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'spec_helper'
2+
load File.expand_path('../../../helpers.rb', __FILE__)
3+
4+
describe Onebox::Engine::CloudMusicOnebox do
5+
before do
6+
FakeWeb.register_uri(:get, 'http://music.163.com/#/song?id=691506', body: response('cloudmusic'), content_type: 'text/html')
7+
end
8+
9+
it 'returns object as the placeholder' do
10+
expect(Onebox.preview('http://music.163.com/#/song?id=691506').placeholder_html).to match(/iframe/)
11+
end
12+
end

0 commit comments

Comments
 (0)