Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix embed urls : now complete (http and https wide) #49

Merged
merged 5 commits into from
Apr 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ video = VideoInfo.new("http://www.dailymotion.com/video/x7lni3")
# video.thumbnail_medium => "http://s2.dmcdn.net/BgWxI/x240-b83.jpg"
# video.thumbnail_large => "http://s2.dmcdn.net/BgWxI/x720-YcV.jpg"
# video.embed_url => "http://www.dailymotion.com/embed/video/x7lni3"
# video.embed_code => "'<iframe src="http://www.dailymotion.com/embed/video/x7lni3" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'"
# video.embed_code => "'<iframe src="//www.dailymotion.com/embed/video/x7lni3" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'"

video = VideoInfo.new("http://vimeo.com/898029")
# video.available? => true
Expand All @@ -46,7 +46,7 @@ video = VideoInfo.new("http://vimeo.com/898029")
# video.thumbnail_medium => "http://b.vimeocdn.com/ts/343/731/34373130_200.jpg"
# video.thumbnail_large => "http://b.vimeocdn.com/ts/343/731/34373130_640.jpg"
# video.embed_url => "http://player.vimeo.com/video/898029"
# video.embed_code => "'<iframe src="http://player.vimeo.com/video/898029?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=0" frameborder="0"></iframe>'"
# video.embed_code => "'<iframe src="//player.vimeo.com/video/898029?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=0" frameborder="0"></iframe>'"

video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4")
# video.available? => true
Expand All @@ -60,7 +60,7 @@ video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4")
# video.thumbnail_medium => "http://i.ytimg.com/vi/mZqGqE0D0n4/mqdefault.jpg"
# video.thumbnail_large => "http://i.ytimg.com/vi/mZqGqE0D0n4/hqdefault.jpg"
# video.embed_url => "http://www.youtube.com/embed/mZqGqE0D0n4"
# video.embed_code => "'<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'"
# video.embed_code => "'<iframe src="//www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'"

playlist = VideoInfo.new("http://www.youtube.com/playlist?p=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr")
# playlist.available? => true
Expand All @@ -71,7 +71,7 @@ playlist = VideoInfo.new("http://www.youtube.com/playlist?p=PL9hW1uS6HUftLdHI6RI
# playlist.thumbnail_medium => "http://i.ytimg.com/vi/8b0aEoxqqC0/mqdefault.jpg"
# playlist.thumbnail_large => "http://i.ytimg.com/vi/8b0aEoxqqC0/hqdefault.jpg"
# playlist.embed_url => "http://www.youtube.com/embed/videoseries?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr"
# playlist.embed_code => "<iframe src="http://www.youtube.com/embed/videoseries?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr" frameborder="0" allowfullscreen="allowfullscreen"></iframe>"
# playlist.embed_code => "<iframe src="//www.youtube.com/embed/videoseries?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr" frameborder="0" allowfullscreen="allowfullscreen"></iframe>"
# playlist.videos => [VideoInfo.new('http://www.youtube.com/watch?v=_Bt3-WsHfB0'), VideoInfo.new('http://www.youtube.com/watch?v=9g2U12SsRns'), VideoInfo.new('http://www.youtube.com/watch?v=8b0aEoxqqC0'), VideoInfo.new('http://www.youtube.com/watch?v=6c3mHikRz0I'), VideoInfo.new('http://www.youtube.com/watch?v=OQVHWsTHcoc')]

playlist = VideoInfo.new("http://vimeo.com/album/2755718")
Expand All @@ -83,7 +83,7 @@ playlist = VideoInfo.new("http://vimeo.com/album/2755718")
# playlist.thumbnail_medium => "http://b.vimeocdn.com/ts/443/595/443595474_200.jpg"
# playlist.thumbnail_large => "http://b.vimeocdn.com/ts/443/595/443595474_640.jpg"
# playlist.embed_url => "player.vimeo.com/hubnut/album/2755718"
# playlist.embed_code => "<iframe src="http://player.vimeo.com/hubnut/album/2755718?autoplay=0&byline=0&portrait=0&title=0" frameborder="0"></iframe>"
# playlist.embed_code => "<iframe src="//player.vimeo.com/hubnut/album/2755718?autoplay=0&byline=0&portrait=0&title=0" frameborder="0"></iframe>"
# playlist.videos => [VideoInfo.new('http://vimeo.com/67977038'), VideoInfo.new('http://vimeo.com/68843810'), VideoInfo.new('http://vimeo.com/69949597'), VideoInfo.new('http://vimeo.com/70388245')]
```

Expand Down Expand Up @@ -111,10 +111,10 @@ You can also include an `iframe_attributes` or `url_attributes` hash to the `emb

``` ruby
VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4").embed_code(iframe_attributes: { width: 800, height: 600, "data-key" => "value" })
=> '<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen" width="800" height="600" data-key="value"></iframe>
=> '<iframe src="//www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen" width="800" height="600" data-key="value"></iframe>

'VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4").embed_code(url_attributes: { autoplay: 1 })
=> '<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4?autoplay=1" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'
=> '<iframe src="//www.youtube.com/embed/mZqGqE0D0n4?autoplay=1" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'
```

Author
Expand Down
3 changes: 1 addition & 2 deletions lib/video_info/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ def _api_url
end

def _embed_url(options)
url_scheme = options.fetch(:url_scheme, 'http')
url_attrs = options.fetch(:url_attributes, {})
url_attrs = _default_url_attributes.merge(url_attrs)

url = "#{url_scheme}://#{embed_url}"
url = embed_url
url += "?#{_hash_to_params(url_attrs)}" unless url_attrs.empty?
url
end
Expand Down
2 changes: 1 addition & 1 deletion lib/video_info/providers/dailymotion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def keywords
end

def embed_url
"www.dailymotion.com/embed/video/#{video_id}"
"//www.dailymotion.com/embed/video/#{video_id}"
end

def date
Expand Down
2 changes: 1 addition & 1 deletion lib/video_info/providers/vimeo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def keywords
end

def embed_url
"player.vimeo.com/video/#{video_id}"
"//player.vimeo.com/video/#{video_id}"
end

def date
Expand Down
2 changes: 1 addition & 1 deletion lib/video_info/providers/vimeoplaylist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def videos
end

def embed_url
"player.vimeo.com/hubnut/album/#{playlist_id}"
"//player.vimeo.com/hubnut/album/#{playlist_id}"
end

%w[width height date keywords duration view_count].each do |method|
Expand Down
2 changes: 1 addition & 1 deletion lib/video_info/providers/vkontakte.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def view_count
end

def embed_url
"vk.com/video_ext.php?oid=#{video_owner}&id=#{video_id}&hash=#{_data_hash}"
"//vk.com/video_ext.php?oid=#{video_owner}&id=#{video_id}&hash=#{_data_hash}"
end

def duration
Expand Down
2 changes: 1 addition & 1 deletion lib/video_info/providers/youtube.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def duration
end

def embed_url
"www.youtube.com/embed/#{video_id}"
"//www.youtube.com/embed/#{video_id}"
end

def date
Expand Down
2 changes: 1 addition & 1 deletion lib/video_info/providers/youtubeplaylist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def videos
end

def embed_url
"www.youtube.com/embed/videoseries?list=#{playlist_id}"
"//www.youtube.com/embed/videoseries?list=#{playlist_id}"
end

def description
Expand Down
10 changes: 3 additions & 7 deletions spec/lib/video_info/provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def _url_regex
end

def embed_url
"foo.com"
"//foo.com"
end

def _default_url_attributes; {} end
Expand Down Expand Up @@ -44,16 +44,12 @@ def _default_iframe_attributes; {} end
end

describe "embed_code" do
it "supports url_scheme option" do
expect(provider.embed_code(url_scheme: 'https')).to eq '<iframe src="https://foo.com" frameborder="0"></iframe>'
end

it "supports url_attributes option" do
expect(provider.embed_code(url_attributes: { foo: 'bar' })).to eq '<iframe src="http://foo.com?foo=bar" frameborder="0"></iframe>'
expect(provider.embed_code(url_attributes: { foo: 'bar' })).to eq '<iframe src="//foo.com?foo=bar" frameborder="0"></iframe>'
end

it "supports url_attributes option" do
expect(provider.embed_code(iframe_attributes: { foo: 'bar' })).to eq '<iframe src="http://foo.com" frameborder="0" foo="bar"></iframe>'
expect(provider.embed_code(iframe_attributes: { foo: 'bar' })).to eq '<iframe src="//foo.com" frameborder="0" foo="bar"></iframe>'
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/video_info/providers/dailymotion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
its(:provider) { should eq 'Dailymotion' }
its(:video_id) { should eq 'x7lni3' }
its(:url) { should eq 'http://www.dailymotion.com/video/x7lni3' }
its(:embed_url) { should eq 'www.dailymotion.com/embed/video/x7lni3' }
its(:embed_code) { should eq '<iframe src="http://www.dailymotion.com/embed/video/x7lni3?autoplay=0" frameborder="0"></iframe>' }
its(:embed_url) { should eq '//www.dailymotion.com/embed/video/x7lni3' }
its(:embed_code) { should eq '<iframe src="//www.dailymotion.com/embed/video/x7lni3?autoplay=0" frameborder="0"></iframe>' }
its(:title) { should eq 'Mario Kart (Rémi Gaillard)' }
its(:description) { should eq 'Super Rémi Kart est un jeu vidéo de course développé et édité par N\'Importe Quoi TV. Sa principale originalité vient de sa réalité...<br />L\'aventure continue sur www.nimportequi.com' }
its(:keywords) { should eq ["rémi","remi","gaillard","imposteur","imposture","mario","bros","kart","nintendo","jeux"] }
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/video_info/providers/vimeo_playlist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
its(:provider) { should eq 'Vimeo' }
its(:playlist_id) { should eq '2755718' }
its(:url) { should eq 'http://vimeo.com/album/2755718' }
its(:embed_url) { should eq 'player.vimeo.com/hubnut/album/2755718' }
its(:embed_code) { should eq '<iframe src="http://player.vimeo.com/hubnut/album/2755718?autoplay=0&byline=0&portrait=0&title=0" frameborder="0"></iframe>' }
its(:embed_url) { should eq '//player.vimeo.com/hubnut/album/2755718' }
its(:embed_code) { should eq '<iframe src="//player.vimeo.com/hubnut/album/2755718?autoplay=0&byline=0&portrait=0&title=0" frameborder="0"></iframe>' }
its(:title) { should eq 'The Century Of Self' }
its(:description) { should eq 'The Century of the Self is an award-winning British television documentary series by Adam Curtis, released in 2002.' }
its(:keywords) { should be_nil }
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/video_info/providers/vimeo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
its(:provider) { should eq 'Vimeo' }
its(:video_id) { should eq '898029' }
its(:url) { should eq 'http://www.vimeo.com/898029' }
its(:embed_url) { should eq 'player.vimeo.com/video/898029' }
its(:embed_code) { should eq '<iframe src="http://player.vimeo.com/video/898029?autoplay=0&byline=0&portrait=0&title=0" frameborder="0"></iframe>' }
its(:embed_url) { should eq '//player.vimeo.com/video/898029' }
its(:embed_code) { should eq '<iframe src="//player.vimeo.com/video/898029?autoplay=0&byline=0&portrait=0&title=0" frameborder="0"></iframe>' }
its(:title) { should eq 'Cherry Bloom - King Of The Knife' }
its(:description) { should eq 'The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net' }
its(:keywords) { should eq 'cherry bloom, secret sounds, king of the knife, rock, alternative' }
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/video_info/providers/vkontakte_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
its(:video_owner) { should eq '39576223' }
its(:video_id) { should eq '108370515' }
its(:url) { should eq 'http://vk.com/video39576223_108370515' }
its(:embed_url) { should eq 'vk.com/video_ext.php?oid=39576223&id=108370515&hash=15184dbd085c47af' }
its(:embed_code) { should eq '<iframe src="http://vk.com/video_ext.php?oid=39576223&id=108370515&hash=15184dbd085c47af" frameborder="0" allowfullscreen="allowfullscreen"></iframe>' }
its(:embed_url) { should eq '//vk.com/video_ext.php?oid=39576223&id=108370515&hash=15184dbd085c47af' }
its(:embed_code) { should eq '<iframe src="//vk.com/video_ext.php?oid=39576223&id=108370515&hash=15184dbd085c47af" frameborder="0" allowfullscreen="allowfullscreen"></iframe>' }
its(:title) { should eq 'Я уточка))))) | VK' }
its(:description) { should eq 'это ВЗРЫВ МОЗГА!!! Просто отвал башки...' }
its(:keywords) { should eq 'это ВЗРЫВ МОЗГА!!! Просто отвал башки...' }
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/video_info/providers/youtube_playlist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
its(:provider) { should eq 'YouTube' }
its(:playlist_id) { should eq 'PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr' }
its(:url) { should eq 'http://www.youtube.com/playlist?p=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr' }
its(:embed_url) { should eq 'www.youtube.com/embed/videoseries?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr' }
its(:embed_code) { should eq '<iframe src="http://www.youtube.com/embed/videoseries?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr" frameborder="0" allowfullscreen="allowfullscreen"></iframe>' }
its(:embed_url) { should eq '//www.youtube.com/embed/videoseries?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr' }
its(:embed_code) { should eq '<iframe src="//www.youtube.com/embed/videoseries?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr" frameborder="0" allowfullscreen="allowfullscreen"></iframe>' }
its(:title) { should eq 'YouTube Policy and Copyright' }
its(:description) { should eq 'Learn more about copyright basics, flagging, and the YouTube community.' }
its(:keywords) { should be_nil }
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/video_info/providers/youtube_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
its(:provider) { should eq 'YouTube' }
its(:video_id) { should eq 'mZqGqE0D0n4' }
its(:url) { should eq 'http://www.youtube.com/watch?v=mZqGqE0D0n4' }
its(:embed_url) { should eq 'www.youtube.com/embed/mZqGqE0D0n4' }
its(:embed_code) { should eq '<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen"></iframe>' }
its(:embed_url) { should eq '//www.youtube.com/embed/mZqGqE0D0n4' }
its(:embed_code) { should eq '<iframe src="//www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen"></iframe>' }
its(:title) { should eq 'Cherry Bloom - King Of The Knife' }
its(:description) { should eq 'The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net' }
its(:keywords) { should be_nil }
Expand Down