video_info 1.6.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -3
- data/Gemfile +1 -1
- data/README.md +11 -11
- data/Rakefile +1 -1
- data/lib/video_info.rb +30 -7
- data/lib/video_info/provider.rb +15 -8
- data/lib/video_info/providers/vimeo.rb +7 -11
- data/lib/video_info/providers/vkontakte.rb +30 -49
- data/lib/video_info/providers/youtube.rb +5 -5
- data/lib/video_info/version.rb +2 -2
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/date/.yml +14 -14
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/description/.yml +16 -14
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/duration/.yml +17 -15
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/height/.yml +16 -14
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/keywords/.yml +17 -15
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/thumbnail_large/.yml +15 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/thumbnail_medium/.yml +16 -14
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/thumbnail_small/.yml +15 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/title/.yml +16 -14
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/view_count/.yml +17 -15
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/width/.yml +16 -14
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/description/.yml +1024 -1336
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/duration/.yml +1024 -1336
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/embed_code/.yml +1036 -1348
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/embed_url/.yml +1036 -1348
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/height/.yml +1024 -1336
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/keywords/.yml +1098 -0
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/title/.yml +1036 -1348
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/view_count/.yml +1024 -1336
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/width/.yml +1024 -1336
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/date/.yml +14 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/description/.yml +14 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/duration/.yml +14 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/keywords/.yml +14 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/thumbnail_large/.yml +14 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/thumbnail_medium/.yml +14 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/thumbnail_small/.yml +14 -13
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/title/.yml +16 -15
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/view_count/.yml +14 -13
- data/spec/lib/video_info/provider_spec.rb +29 -9
- data/spec/lib/video_info/providers/vimeo_spec.rb +11 -11
- data/spec/lib/video_info/providers/vkontakte_spec.rb +4 -3
- data/spec/lib/video_info/providers/youtube_spec.rb +19 -19
- data/spec/lib/video_info_spec.rb +23 -23
- data/spec/spec_helper.rb +8 -2
- data/video_info.gemspec +5 -2
- metadata +6 -104
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/embed_code/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/embed_url/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/provider/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/url/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/video_id/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_and_iframe_attributes/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_and_url_attributes/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_in_/group/_url/provider/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_in_/group/_url/video_id/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_in_text/provider/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_in_text/video_id/.yml +0 -69
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/date/.yml +0 -1410
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/provider/.yml +0 -1410
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/url/.yml +0 -1410
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/video_id/.yml +0 -1410
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/video_owner/.yml +0 -1369
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_arbitrary_iframe_attributes/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_arbitrary_iframe_attributes/provider/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_iframe_attributes/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_iframe_attributes/provider/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_JM9NgvjjVng_in_youtu_be_url/provider/.yml +0 -65
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_JM9NgvjjVng_in_youtu_be_url/video_id/.yml +0 -65
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_after_params/provider/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_after_params/url/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_after_params/video_id/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_e_path/provider/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_e_path/video_id/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_embed_path/provider/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_embed_path/video_id/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_path/provider/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_path/video_id/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_user_url/provider/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_user_url/url/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_user_url/video_id/.yml +0 -66
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_Xp6CXF-Cesg/provider/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_Xp6CXF-Cesg/video_id/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/embed_code/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/embed_url/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/height/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/provider/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/url/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/video_id/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/width/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_oQ49W_xKzKA/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_oQ49W_xKzKA/provider/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_oQ49W_xKzKA/video_id/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_url_in_text/provider/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_url_in_text/video_id/.yml +0 -62
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/without_http_or_www/provider/.yml +0 -65
- data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/without_http_or_www/video_id/.yml +0 -65
data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/view_count/.yml
CHANGED
@@ -8,7 +8,7 @@ http_interactions:
|
|
8
8
|
string: ''
|
9
9
|
headers:
|
10
10
|
User-Agent:
|
11
|
-
- VideoInfo/
|
11
|
+
- VideoInfo/2.0.0
|
12
12
|
Accept-Encoding:
|
13
13
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
14
|
Accept:
|
@@ -25,9 +25,9 @@ http_interactions:
|
|
25
25
|
Access-Control-Allow-Origin:
|
26
26
|
- '*'
|
27
27
|
Expires:
|
28
|
-
-
|
28
|
+
- Fri, 25 Oct 2013 20:34:01 GMT
|
29
29
|
Date:
|
30
|
-
-
|
30
|
+
- Fri, 25 Oct 2013 20:34:01 GMT
|
31
31
|
Cache-Control:
|
32
32
|
- private, max-age=300, no-transform
|
33
33
|
Vary:
|
@@ -35,9 +35,9 @@ http_interactions:
|
|
35
35
|
Gdata-Version:
|
36
36
|
- '2.1'
|
37
37
|
Etag:
|
38
|
-
- W/"
|
38
|
+
- W/"CkAMQ347eCp7I2A9Wh5SE08."
|
39
39
|
Last-Modified:
|
40
|
-
- Wed,
|
40
|
+
- Wed, 09 Oct 2013 12:13:02 GMT
|
41
41
|
X-Content-Type-Options:
|
42
42
|
- nosniff
|
43
43
|
X-Frame-Options:
|
@@ -45,18 +45,19 @@ http_interactions:
|
|
45
45
|
X-Xss-Protection:
|
46
46
|
- 1; mode=block
|
47
47
|
Content-Length:
|
48
|
-
- '
|
48
|
+
- '4652'
|
49
49
|
Server:
|
50
50
|
- GSE
|
51
51
|
Alternate-Protocol:
|
52
52
|
- 80:quic
|
53
53
|
body:
|
54
54
|
encoding: UTF-8
|
55
|
-
string: '{"version":"1.0","encoding":"UTF-8","entry":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$media":"http://search.yahoo.com/mrss/","xmlns$gd":"http://schemas.google.com/g/2005","xmlns$yt":"http://gdata.youtube.com/schemas/2007","gd$etag":"W/\"
|
56
|
-
Bloom - King Of The Knife"},"content":{"type":"application/x-shockwave-flash","src":"http://www.youtube.com/v/mZqGqE0D0n4?version=3&f=videos&app=youtube_gdata"},"link":[{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=mZqGqE0D0n4&feature=youtube_gdata"},{"rel":"http://gdata.youtube.com/schemas/2007#video.responses","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/mZqGqE0D0n4/responses?v=2"},{"rel":"http://gdata.youtube.com/schemas/2007#video.related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/mZqGqE0D0n4/related?v=2"},{"rel":"http://gdata.youtube.com/schemas/2007#uploader","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/users/zxQk-rZGowoqMBKxGD5jSA?v=2"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/mZqGqE0D0n4?v=2"}],"author":[{"name":{"$t":"
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
string: '{"version":"1.0","encoding":"UTF-8","entry":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$media":"http://search.yahoo.com/mrss/","xmlns$gd":"http://schemas.google.com/g/2005","xmlns$yt":"http://gdata.youtube.com/schemas/2007","gd$etag":"W/\"CkAMQ347eCp7I2A9Wh5SE08.\"","id":{"$t":"tag:youtube.com,2008:video:mZqGqE0D0n4"},"published":{"$t":"2008-04-12T22:25:35.000Z"},"updated":{"$t":"2013-10-09T12:13:02.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://gdata.youtube.com/schemas/2007#video"},{"scheme":"http://gdata.youtube.com/schemas/2007/categories.cat","term":"Music","label":"Music"}],"title":{"$t":"Cherry
|
56
|
+
Bloom - King Of The Knife"},"content":{"type":"application/x-shockwave-flash","src":"http://www.youtube.com/v/mZqGqE0D0n4?version=3&f=videos&app=youtube_gdata"},"link":[{"rel":"alternate","type":"text/html","href":"http://www.youtube.com/watch?v=mZqGqE0D0n4&feature=youtube_gdata"},{"rel":"http://gdata.youtube.com/schemas/2007#video.responses","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/mZqGqE0D0n4/responses?v=2"},{"rel":"http://gdata.youtube.com/schemas/2007#video.related","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/mZqGqE0D0n4/related?v=2"},{"rel":"http://gdata.youtube.com/schemas/2007#uploader","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/users/zxQk-rZGowoqMBKxGD5jSA?v=2"},{"rel":"self","type":"application/atom+xml","href":"http://gdata.youtube.com/feeds/api/videos/mZqGqE0D0n4?v=2"}],"author":[{"name":{"$t":"Cherry
|
57
|
+
Bloom"},"uri":{"$t":"http://gdata.youtube.com/feeds/api/users/cherrybloomband"},"yt$userId":{"$t":"zxQk-rZGowoqMBKxGD5jSA"}}],"yt$accessControl":[{"action":"comment","permission":"allowed"},{"action":"commentVote","permission":"allowed"},{"action":"videoRespond","permission":"allowed"},{"action":"rate","permission":"allowed"},{"action":"embed","permission":"allowed"},{"action":"list","permission":"allowed"},{"action":"autoPlay","permission":"allowed"},{"action":"syndicate","permission":"allowed"}],"gd$comments":{"gd$feedLink":{"rel":"http://gdata.youtube.com/schemas/2007#comments","href":"http://gdata.youtube.com/feeds/api/videos/mZqGqE0D0n4/comments?v=2","countHint":15}},"media$group":{"media$category":[{"$t":"Music","label":"Music","scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"}],"media$content":[{"url":"http://www.youtube.com/v/mZqGqE0D0n4?version=3&f=videos&app=youtube_gdata","type":"application/x-shockwave-flash","medium":"video","isDefault":"true","expression":"full","duration":175,"yt$format":5},{"url":"rtsp://r5---sn-4g57kuez.c.youtube.com/CiILENy73wIaGQl-0gNNqIaamRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp","type":"video/3gpp","medium":"video","expression":"full","duration":175,"yt$format":1},{"url":"rtsp://r5---sn-4g57kuez.c.youtube.com/CiILENy73wIaGQl-0gNNqIaamRMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp","type":"video/3gpp","medium":"video","expression":"full","duration":175,"yt$format":6}],"media$credit":[{"$t":"cherrybloomband","role":"uploader","scheme":"urn:youtube","yt$display":"Cherry
|
58
|
+
Bloom"}],"media$description":{"$t":"The first video from the upcoming album
|
59
|
+
Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net","type":"plain"},"media$keywords":{},"media$license":{"$t":"youtube","type":"text/html","href":"http://www.youtube.com/t/terms"},"media$player":{"url":"http://www.youtube.com/watch?v=mZqGqE0D0n4&feature=youtube_gdata_player"},"media$thumbnail":[{"url":"http://i1.ytimg.com/vi/mZqGqE0D0n4/default.jpg","height":90,"width":120,"time":"00:01:27.500","yt$name":"default"},{"url":"http://i1.ytimg.com/vi/mZqGqE0D0n4/mqdefault.jpg","height":180,"width":320,"yt$name":"mqdefault"},{"url":"http://i1.ytimg.com/vi/mZqGqE0D0n4/hqdefault.jpg","height":360,"width":480,"yt$name":"hqdefault"},{"url":"http://i1.ytimg.com/vi/mZqGqE0D0n4/1.jpg","height":90,"width":120,"time":"00:00:43.750","yt$name":"start"},{"url":"http://i1.ytimg.com/vi/mZqGqE0D0n4/2.jpg","height":90,"width":120,"time":"00:01:27.500","yt$name":"middle"},{"url":"http://i1.ytimg.com/vi/mZqGqE0D0n4/3.jpg","height":90,"width":120,"time":"00:02:11.250","yt$name":"end"}],"media$title":{"$t":"Cherry
|
60
|
+
Bloom - King Of The Knife","type":"plain"},"yt$duration":{"seconds":"175"},"yt$uploaded":{"$t":"2008-04-12T22:25:35.000Z"},"yt$uploaderId":{"$t":"UCzxQk-rZGowoqMBKxGD5jSA"},"yt$videoid":{"$t":"mZqGqE0D0n4"}},"gd$rating":{"average":4.822222,"max":5,"min":1,"numRaters":45,"rel":"http://schemas.google.com/g/2005#overall"},"yt$statistics":{"favoriteCount":"0","viewCount":"6264"},"yt$rating":{"numDislikes":"2","numLikes":"43"}}}'
|
60
61
|
http_version:
|
61
|
-
recorded_at:
|
62
|
-
recorded_with: VCR 2.
|
62
|
+
recorded_at: Fri, 25 Oct 2013 20:34:02 GMT
|
63
|
+
recorded_with: VCR 2.6.0
|
@@ -1,42 +1,62 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe VideoInfo::Provider do
|
4
|
-
|
5
4
|
class ProviderFu < VideoInfo::Provider
|
6
5
|
def _url_regex
|
7
6
|
/foo\/(\d)/
|
8
7
|
end
|
8
|
+
|
9
|
+
def embed_url
|
10
|
+
"foo.com"
|
11
|
+
end
|
12
|
+
|
13
|
+
def _default_url_attributes; {} end
|
14
|
+
def _default_iframe_attributes; {} end
|
9
15
|
end
|
16
|
+
let(:url) { 'url' }
|
17
|
+
let(:options) { { } }
|
18
|
+
let(:provider) { ProviderFu.new('foo/1', options) }
|
10
19
|
|
11
20
|
describe "initialize" do
|
12
|
-
let(:url) { 'url' }
|
13
|
-
let(:options) { { } }
|
14
|
-
let(:provider) { ProviderFu.new(url, options) }
|
15
21
|
|
16
22
|
it { expect { VideoInfo::Provider.new(url) }.to raise_error(NotImplementedError, 'Provider class must implement #_url_regex private method') }
|
17
|
-
it { expect {
|
23
|
+
it { expect { provider.data }.to raise_error(NotImplementedError, 'Provider class must implement #_api_url private method') }
|
18
24
|
|
19
25
|
it "sets default user_agent options" do
|
20
|
-
provider.options.
|
26
|
+
expect(provider.options).to eq({ 'User-Agent' => "VideoInfo/#{VideoInfo::VERSION}" })
|
21
27
|
end
|
22
28
|
|
23
29
|
context "with custom User-Agent options" do
|
24
30
|
let(:options) { { 'User-Agent' => 'Test User Agent / 1.0' } }
|
25
31
|
|
26
32
|
it "sets the option" do
|
27
|
-
provider.options.
|
33
|
+
expect(provider.options).to eq({ 'User-Agent' => 'Test User Agent / 1.0' })
|
28
34
|
end
|
29
35
|
end
|
30
36
|
|
31
37
|
context "with Referer options" do
|
32
|
-
let(:options) { { :
|
38
|
+
let(:options) { { referer: 'http://google.com' } }
|
33
39
|
|
34
40
|
it "sets the option" do
|
35
|
-
provider.options.
|
41
|
+
expect(provider.options).to include({ 'Referer' => 'http://google.com' })
|
36
42
|
end
|
37
43
|
end
|
38
44
|
end
|
39
45
|
|
46
|
+
describe "embed_code" do
|
47
|
+
it "supports url_scheme option" do
|
48
|
+
expect(provider.embed_code(url_scheme: 'https')).to eq '<iframe src="https://foo.com" frameborder="0"></iframe>'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "supports url_attributes option" do
|
52
|
+
expect(provider.embed_code(url_attributes: { foo: 'bar' })).to eq '<iframe src="http://foo.com?foo=bar" frameborder="0"></iframe>'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "supports url_attributes option" do
|
56
|
+
expect(provider.embed_code(iframe_attributes: { foo: 'bar' })).to eq '<iframe src="http://foo.com" frameborder="0" foo="bar"></iframe>'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
40
60
|
describe ".usable?" do
|
41
61
|
it { expect { VideoInfo::Provider.usable?('url') }.to raise_error(NotImplementedError, 'Provider class must implement .usable? public method') }
|
42
62
|
end
|
@@ -17,12 +17,12 @@ describe VideoInfo::Providers::Vimeo do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
context "with video 898029", :vcr do
|
20
|
-
subject { VideoInfo.
|
20
|
+
subject { VideoInfo.new('http://www.vimeo.com/898029') }
|
21
21
|
|
22
22
|
its(:provider) { should eq 'Vimeo' }
|
23
23
|
its(:video_id) { should eq '898029' }
|
24
|
-
its(:url) { should eq 'http://vimeo.com/898029' }
|
25
|
-
its(:embed_url) { should eq '
|
24
|
+
its(:url) { should eq 'http://www.vimeo.com/898029' }
|
25
|
+
its(:embed_url) { should eq 'player.vimeo.com/video/898029' }
|
26
26
|
its(:embed_code) { should eq '<iframe src="http://player.vimeo.com/video/898029?autoplay=0&byline=0&portrait=0&title=0" frameborder="0"></iframe>' }
|
27
27
|
its(:title) { should eq 'Cherry Bloom - King Of The Knife' }
|
28
28
|
its(:description) { should eq 'The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net' }
|
@@ -38,34 +38,34 @@ describe VideoInfo::Providers::Vimeo do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
context "with video 898029 and url_attributes", :vcr do
|
41
|
-
subject { VideoInfo.
|
41
|
+
subject { VideoInfo.new('http://www.vimeo.com/898029') }
|
42
42
|
|
43
|
-
it { subject.embed_code(:
|
43
|
+
it { expect(subject.embed_code(url_attributes: { autoplay: 1 })).to match(/autoplay=1/) }
|
44
44
|
end
|
45
45
|
|
46
46
|
context "with video 898029 and iframe_attributes", :vcr do
|
47
|
-
subject { VideoInfo.
|
47
|
+
subject { VideoInfo.new('http://www.vimeo.com/898029') }
|
48
48
|
|
49
|
-
it { subject.embed_code(:
|
50
|
-
it { subject.embed_code(:
|
49
|
+
it { expect(subject.embed_code(iframe_attributes: { width: 800, height: 600 })).to match(/width="800"/) }
|
50
|
+
it { expect(subject.embed_code(iframe_attributes: { width: 800, height: 600 })).to match(/height="600"/) }
|
51
51
|
end
|
52
52
|
|
53
53
|
context "with video 898029 in /group/ url", :vcr do
|
54
|
-
subject { VideoInfo.
|
54
|
+
subject { VideoInfo.new('http://vimeo.com/groups/1234/videos/898029') }
|
55
55
|
|
56
56
|
its(:provider) { should eq 'Vimeo' }
|
57
57
|
its(:video_id) { should eq '898029' }
|
58
58
|
end
|
59
59
|
|
60
60
|
context "with video 898029 in /group/ url", :vcr do
|
61
|
-
subject { VideoInfo.
|
61
|
+
subject { VideoInfo.new('http://player.vimeo.com/video/898029') }
|
62
62
|
|
63
63
|
its(:provider) { should eq 'Vimeo' }
|
64
64
|
its(:video_id) { should eq '898029' }
|
65
65
|
end
|
66
66
|
|
67
67
|
context "with video 898029 in text", :vcr do
|
68
|
-
subject { VideoInfo.
|
68
|
+
subject { VideoInfo.new('<a href="http://www.vimeo.com/898029">http://www.vimeo.com/898029</a>') }
|
69
69
|
|
70
70
|
its(:provider) { should eq 'Vimeo' }
|
71
71
|
its(:video_id) { should eq '898029' }
|
@@ -19,16 +19,17 @@ describe VideoInfo::Providers::Vkontakte do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
context "with video 39576223_108370515", :vcr do
|
22
|
-
subject { VideoInfo.
|
22
|
+
subject { VideoInfo.new('http://vk.com/video39576223_108370515') }
|
23
23
|
|
24
24
|
its(:provider) { should eq 'Vkontakte' }
|
25
25
|
its(:video_owner) { should eq '39576223' }
|
26
26
|
its(:video_id) { should eq '108370515' }
|
27
27
|
its(:url) { should eq 'http://vk.com/video39576223_108370515' }
|
28
|
-
its(:embed_url) { should eq '
|
28
|
+
its(:embed_url) { should eq 'vk.com/video_ext.php?oid=39576223&id=108370515&hash=15184dbd085c47af' }
|
29
29
|
its(:embed_code) { should eq '<iframe src="http://vk.com/video_ext.php?oid=39576223&id=108370515&hash=15184dbd085c47af" frameborder="0" allowfullscreen="allowfullscreen"></iframe>' }
|
30
|
-
its(:title) { should eq 'Я уточка)))))' }
|
30
|
+
its(:title) { should eq 'Я уточка))))) | VK' }
|
31
31
|
its(:description) { should eq 'это ВЗРЫВ МОЗГА!!! Просто отвал башки...' }
|
32
|
+
its(:keywords) { should eq 'это ВЗРЫВ МОЗГА!!! Просто отвал башки...' }
|
32
33
|
its(:duration) { should eq 183 }
|
33
34
|
its(:width) { should eq 320 }
|
34
35
|
its(:height) { should eq 240 }
|
@@ -22,12 +22,12 @@ describe VideoInfo::Providers::Youtube do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
context "with video mZqGqE0D0n4", :vcr do
|
25
|
-
subject { VideoInfo.
|
25
|
+
subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
|
26
26
|
|
27
27
|
its(:provider) { should eq 'YouTube' }
|
28
28
|
its(:video_id) { should eq 'mZqGqE0D0n4' }
|
29
29
|
its(:url) { should eq 'http://www.youtube.com/watch?v=mZqGqE0D0n4' }
|
30
|
-
its(:embed_url) { should eq '
|
30
|
+
its(:embed_url) { should eq 'www.youtube.com/embed/mZqGqE0D0n4' }
|
31
31
|
its(:embed_code) { should eq '<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen"></iframe>' }
|
32
32
|
its(:title) { should eq 'Cherry Bloom - King Of The Knife' }
|
33
33
|
its(:description) { should eq 'The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net' }
|
@@ -43,27 +43,27 @@ describe VideoInfo::Providers::Youtube do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
context "with video oQ49W_xKzKA", :vcr do
|
46
|
-
subject { VideoInfo.
|
46
|
+
subject { VideoInfo.new('http://www.youtube.com/watch?v=oQ49W_xKzKA') }
|
47
47
|
|
48
|
-
it { subject.embed_code(:
|
48
|
+
it { expect(subject.embed_code(url_attributes: { autoplay: 1 })).to match(/autoplay=1/) }
|
49
49
|
end
|
50
50
|
|
51
51
|
context "with video oQ49W_xKzKA", :vcr do
|
52
|
-
subject { VideoInfo.
|
52
|
+
subject { VideoInfo.new('http://www.youtube.com/watch?v=oQ49W_xKzKA') }
|
53
53
|
|
54
54
|
its(:provider) { should eq 'YouTube' }
|
55
55
|
its(:video_id) { should eq 'oQ49W_xKzKA' }
|
56
56
|
end
|
57
57
|
|
58
58
|
context "with video Xp6CXF-Cesg", :vcr do
|
59
|
-
subject { VideoInfo.
|
59
|
+
subject { VideoInfo.new('http://www.youtube.com/watch?v=Xp6CXF-Cesg') }
|
60
60
|
|
61
61
|
its(:provider) { should eq 'YouTube' }
|
62
62
|
its(:video_id) { should eq 'Xp6CXF-Cesg' }
|
63
63
|
end
|
64
64
|
|
65
65
|
context "with video VeasFckfMHY in user url", :vcr do
|
66
|
-
subject { VideoInfo.
|
66
|
+
subject { VideoInfo.new('http://www.youtube.com/user/EducatorVids3?v=VeasFckfMHY') }
|
67
67
|
|
68
68
|
its(:provider) { should eq 'YouTube' }
|
69
69
|
its(:video_id) { should eq 'VeasFckfMHY' }
|
@@ -71,7 +71,7 @@ describe VideoInfo::Providers::Youtube do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
context "with video VeasFckfMHY after params", :vcr do
|
74
|
-
subject { VideoInfo.
|
74
|
+
subject { VideoInfo.new('http://www.youtube.com/watch?feature=player_profilepage&v=VeasFckfMHY') }
|
75
75
|
|
76
76
|
its(:provider) { should eq 'YouTube' }
|
77
77
|
its(:video_id) { should eq 'VeasFckfMHY' }
|
@@ -79,60 +79,60 @@ describe VideoInfo::Providers::Youtube do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
context "with video VeasFckfMHY in path", :vcr do
|
82
|
-
subject { VideoInfo.
|
82
|
+
subject { VideoInfo.new('http://www.youtube.com/v/VeasFckfMHY') }
|
83
83
|
|
84
84
|
its(:provider) { should eq 'YouTube' }
|
85
85
|
its(:video_id) { should eq 'VeasFckfMHY' }
|
86
86
|
end
|
87
87
|
|
88
88
|
context "with video VeasFckfMHY in e path", :vcr do
|
89
|
-
subject { VideoInfo.
|
89
|
+
subject { VideoInfo.new('http://www.youtube.com/e/VeasFckfMHY') }
|
90
90
|
|
91
91
|
its(:provider) { should eq 'YouTube' }
|
92
92
|
its(:video_id) { should eq 'VeasFckfMHY' }
|
93
93
|
end
|
94
94
|
|
95
95
|
context "with video VeasFckfMHY in embed path", :vcr do
|
96
|
-
subject { VideoInfo.
|
96
|
+
subject { VideoInfo.new('http://www.youtube.com/embed/VeasFckfMHY') }
|
97
97
|
|
98
98
|
its(:provider) { should eq 'YouTube' }
|
99
99
|
its(:video_id) { should eq 'VeasFckfMHY' }
|
100
100
|
end
|
101
101
|
|
102
102
|
context "with video JM9NgvjjVng in youtu.be url", :vcr do
|
103
|
-
subject { VideoInfo.
|
103
|
+
subject { VideoInfo.new('http://youtu.be/JM9NgvjjVng') }
|
104
104
|
|
105
105
|
its(:provider) { should eq 'YouTube' }
|
106
106
|
its(:video_id) { should eq 'JM9NgvjjVng' }
|
107
107
|
end
|
108
108
|
|
109
109
|
context 'without http or www', :vcr do
|
110
|
-
subject { VideoInfo.
|
110
|
+
subject { VideoInfo.new('youtu.be/JM9NgvjjVng') }
|
111
111
|
|
112
112
|
its(:provider) { should == 'YouTube' }
|
113
113
|
its(:video_id) { should eq 'JM9NgvjjVng' }
|
114
114
|
end
|
115
115
|
|
116
116
|
context "with video url in text", :vcr do
|
117
|
-
subject { VideoInfo.
|
117
|
+
subject { VideoInfo.new('<a href="http://www.youtube.com/watch?v=mZqGqE0D0n4">http://www.youtube.com/watch?v=mZqGqE0D0n4</a>') }
|
118
118
|
|
119
119
|
its(:provider) { should == 'YouTube' }
|
120
120
|
its(:video_id) { should == 'mZqGqE0D0n4' }
|
121
121
|
end
|
122
122
|
|
123
123
|
context "with iframe attributes", :vcr do
|
124
|
-
subject { VideoInfo.
|
124
|
+
subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
|
125
125
|
|
126
126
|
its(:provider) { should == 'YouTube' }
|
127
|
-
it { subject.embed_code(:
|
128
|
-
it { subject.embed_code(:
|
127
|
+
it { expect(subject.embed_code(iframe_attributes: { width: 800, height: 600 })).to match(/width="800"/) }
|
128
|
+
it { expect(subject.embed_code(iframe_attributes: { width: 800, height: 600 })).to match(/height="600"/) }
|
129
129
|
end
|
130
130
|
|
131
131
|
context "with arbitrary iframe_attributes", :vcr do
|
132
|
-
subject { VideoInfo.
|
132
|
+
subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
|
133
133
|
|
134
134
|
its(:provider) { should == 'YouTube' }
|
135
|
-
it { subject.embed_code(:
|
135
|
+
it { expect(subject.embed_code(iframe_attributes: { :'data-colorbox' => true })).to match(/data-colorbox="true"/) }
|
136
136
|
end
|
137
137
|
|
138
138
|
end
|
data/spec/lib/video_info_spec.rb
CHANGED
@@ -2,48 +2,48 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe VideoInfo do
|
4
4
|
|
5
|
-
describe "
|
5
|
+
describe "#initialize" do
|
6
6
|
let(:url) { 'url' }
|
7
|
-
let(:options) { { :
|
8
|
-
let(:provider) { double('provider') }
|
7
|
+
let(:options) { { foo: :bar } }
|
8
|
+
let(:provider) { double('provider', provider: 'Provider') }
|
9
9
|
|
10
10
|
it "uses the first usable provider" do
|
11
|
-
VideoInfo::Providers::Vimeo.
|
12
|
-
VideoInfo::Providers::Vkontakte.
|
13
|
-
VideoInfo::Providers::Youtube.
|
14
|
-
VideoInfo::Providers::Youtube.
|
11
|
+
VideoInfo::Providers::Vimeo.stub(:usable?) { false }
|
12
|
+
VideoInfo::Providers::Vkontakte.stub(:usable?) { false }
|
13
|
+
VideoInfo::Providers::Youtube.stub(:usable?) { true }
|
14
|
+
VideoInfo::Providers::Youtube.stub(:new) { provider }
|
15
15
|
|
16
|
-
VideoInfo.
|
16
|
+
expect(VideoInfo.new(url, options).provider).to eq 'Provider'
|
17
17
|
end
|
18
18
|
|
19
|
-
it "
|
20
|
-
VideoInfo::Providers::Vimeo.
|
21
|
-
VideoInfo::Providers::Vkontakte.
|
22
|
-
VideoInfo::Providers::Youtube.
|
19
|
+
it "raise when no providers are usable" do
|
20
|
+
VideoInfo::Providers::Vimeo.stub(:usable?) { false }
|
21
|
+
VideoInfo::Providers::Vkontakte.stub(:usable?) { false }
|
22
|
+
VideoInfo::Providers::Youtube.stub(:usable?) { false }
|
23
23
|
|
24
|
-
VideoInfo.
|
24
|
+
expect { VideoInfo.new(url, options) }.to raise_error(VideoInfo::UrlError)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
describe ".usable?" do
|
29
29
|
let(:url) { 'url' }
|
30
|
-
let(:
|
31
|
-
let(:provider) { double('provider') }
|
30
|
+
let(:provider) { double('provider', new: true) }
|
32
31
|
|
33
32
|
it "returns true when a provider is usable" do
|
34
|
-
VideoInfo::Providers::Vimeo.
|
35
|
-
VideoInfo::Providers::Vkontakte.
|
36
|
-
VideoInfo::Providers::Youtube.
|
33
|
+
VideoInfo::Providers::Vimeo.stub(:usable?) { false }
|
34
|
+
VideoInfo::Providers::Vkontakte.stub(:usable?) { false }
|
35
|
+
VideoInfo::Providers::Youtube.stub(:usable?) { true }
|
36
|
+
VideoInfo::Providers::Youtube.stub(:new) { true }
|
37
37
|
|
38
|
-
VideoInfo.usable?(url).
|
38
|
+
expect(VideoInfo.usable?(url)).to be_true
|
39
39
|
end
|
40
40
|
|
41
41
|
it "returns false when no providers are usable" do
|
42
|
-
VideoInfo::Providers::Vimeo.
|
43
|
-
VideoInfo::Providers::Vkontakte.
|
44
|
-
VideoInfo::Providers::Youtube.
|
42
|
+
VideoInfo::Providers::Vimeo.stub(:usable?) { false }
|
43
|
+
VideoInfo::Providers::Vkontakte.stub(:usable?) { false }
|
44
|
+
VideoInfo::Providers::Youtube.stub(:usable?) { false }
|
45
45
|
|
46
|
-
VideoInfo.usable?(url).
|
46
|
+
expect(VideoInfo.usable?(url)).to be_false
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
data/spec/spec_helper.rb
CHANGED
@@ -9,14 +9,20 @@ end
|
|
9
9
|
|
10
10
|
VCR.configure do |config|
|
11
11
|
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
12
|
-
config.default_cassette_options = {
|
12
|
+
config.default_cassette_options = {
|
13
|
+
record: :new_episodes,
|
14
|
+
re_record_interval: 7 * 24 * 60 * 60
|
15
|
+
}
|
13
16
|
config.hook_into :webmock
|
14
17
|
config.configure_rspec_metadata!
|
15
18
|
end
|
16
19
|
|
17
20
|
RSpec.configure do |config|
|
18
21
|
config.color_enabled = true
|
19
|
-
config.filter_run :
|
22
|
+
config.filter_run focus: true
|
20
23
|
config.run_all_when_everything_filtered = true
|
21
24
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
25
|
+
config.expect_with :rspec do |c|
|
26
|
+
c.syntax = :expect
|
27
|
+
end
|
22
28
|
end
|
data/video_info.gemspec
CHANGED
@@ -11,16 +11,19 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.author = 'Thibaud Guillaume-Gentil'
|
12
12
|
s.email = 'thibaud@thibaud.me'
|
13
13
|
s.homepage = 'https://rubygems.org/gems/video_info'
|
14
|
-
s.summary = 'Vimeo &
|
15
|
-
s.description = 'Get video info from YouTube and
|
14
|
+
s.summary = 'YouTube, Vimeo & VK parser'
|
15
|
+
s.description = 'Get video info from YouTube, Vimeo and VK url.'
|
16
16
|
|
17
17
|
s.files = `git ls-files`.split($/)
|
18
18
|
s.test_files = s.files.grep(%r{^spec/})
|
19
19
|
s.require_path = 'lib'
|
20
20
|
|
21
|
+
s.required_ruby_version = '>= 1.9.2'
|
22
|
+
|
21
23
|
s.add_dependency 'addressable'
|
22
24
|
s.add_dependency 'multi_json'
|
23
25
|
s.add_dependency 'htmlentities'
|
26
|
+
|
24
27
|
s.add_development_dependency 'bundler', '>= 1.3.5'
|
25
28
|
s.add_development_dependency 'rake'
|
26
29
|
s.add_development_dependency 'rspec'
|