video_info 2.4.2 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +1 -3
  4. data/README.md +33 -2
  5. data/lib/video_info.rb +44 -2
  6. data/lib/video_info/provider.rb +21 -4
  7. data/lib/video_info/providers/vimeo.rb +81 -9
  8. data/lib/video_info/providers/vimeoplaylist.rb +14 -13
  9. data/lib/video_info/providers/vkontakte.rb +1 -1
  10. data/lib/video_info/providers/youtube.rb +20 -51
  11. data/lib/video_info/providers/youtube_api.rb +72 -0
  12. data/lib/video_info/providers/youtube_scraper.rb +99 -0
  13. data/lib/video_info/providers/youtubeplaylist.rb +28 -29
  14. data/lib/video_info/providers/youtubeplaylist_api.rb +57 -0
  15. data/lib/video_info/providers/youtubeplaylist_scraper.rb +47 -0
  16. data/lib/video_info/version.rb +1 -1
  17. data/spec/lib/video_info/providers/vimeo_playlist_spec.rb +19 -18
  18. data/spec/lib/video_info/providers/vimeo_spec.rb +45 -21
  19. data/spec/lib/video_info/providers/vkontakte_spec.rb +2 -2
  20. data/spec/lib/video_info/providers/youtube_api_spec.rb +392 -0
  21. data/spec/lib/video_info/providers/youtube_playlist_api_spec.rb +173 -0
  22. data/spec/lib/video_info/providers/youtube_playlist_spec.rb +6 -2
  23. data/spec/lib/video_info/providers/youtube_spec.rb +83 -6
  24. data/spec/lib/video_info_spec.rb +30 -0
  25. data/spec/spec_helper.rb +2 -0
  26. data/video_info.gemspec +4 -1
  27. metadata +55 -196
  28. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/_available_/with_This_video_does_not_exist_or_has_been_deleted_/_available_/.yml +0 -60
  29. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/_available_/with_valid_video/_available_/.yml +0 -59
  30. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_date/.yml +0 -62
  31. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_description/.yml +0 -62
  32. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_duration/.yml +0 -62
  33. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_keywords/.yml +0 -62
  34. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_thumbnail_large/.yml +0 -62
  35. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_thumbnail_medium/.yml +0 -62
  36. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_thumbnail_small/.yml +0 -62
  37. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_title/.yml +0 -62
  38. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_view_count/.yml +0 -62
  39. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/_available_/with_password_required_video/_available_/.yml +0 -119
  40. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/_available_/with_this_video_does_not_exist_video/_available_/.yml +0 -72
  41. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/_available_/with_valid_video/_available_/.yml +0 -76
  42. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_date/.yml +0 -83
  43. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_description/.yml +0 -83
  44. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_duration/.yml +0 -83
  45. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_height/.yml +0 -83
  46. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_keywords/.yml +0 -83
  47. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_thumbnail_large/.yml +0 -83
  48. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_thumbnail_medium/.yml +0 -83
  49. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_thumbnail_small/.yml +0 -83
  50. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_title/.yml +0 -83
  51. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_view_count/.yml +0 -83
  52. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/_width/.yml +0 -83
  53. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/_available_/with_invalid_playlist/_available_/.yml +0 -72
  54. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/_available_/with_valid_playlist/_available_/.yml +0 -76
  55. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_1921098/_description/.yml +0 -81
  56. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_1921098/_thumbnail_large/.yml +0 -81
  57. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_1921098/_thumbnail_medium/.yml +0 -81
  58. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_1921098/_thumbnail_small/.yml +0 -81
  59. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_1921098/_title/.yml +0 -81
  60. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_VimeoPlaylist/with_playlist_1921098/_videos/.yml +0 -114
  61. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/_available_/with_hashes/available_/.yml +0 -2255
  62. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/_available_/with_invalid_video/available_/.yml +0 -46
  63. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/_available_/with_private_video/available_/.yml +0 -382
  64. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/_available_/with_redirect/available_/.yml +0 -210
  65. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/_available_/with_redirect_to_main_page_for_auth/available_/.yml +0 -46
  66. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/_available_/with_valid_video/available_/.yml +0 -1657
  67. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_kirill_lyanoi_z_video2152699_168591741_2F56fd229a9dfe2dcdbe/description/.yml +0 -730
  68. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_kirill_lyanoi_z_video2152699_168591741_2F56fd229a9dfe2dcdbe/duration/.yml +0 -731
  69. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_kirill_lyanoi_z_video2152699_168591741_2F56fd229a9dfe2dcdbe/embed_code/.yml +0 -732
  70. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_kirill_lyanoi_z_video2152699_168591741_2F56fd229a9dfe2dcdbe/embed_url/.yml +0 -732
  71. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_kirill_lyanoi_z_video2152699_168591741_2F56fd229a9dfe2dcdbe/height/.yml +0 -732
  72. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_kirill_lyanoi_z_video2152699_168591741_2F56fd229a9dfe2dcdbe/keywords/.yml +0 -732
  73. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_kirill_lyanoi_z_video2152699_168591741_2F56fd229a9dfe2dcdbe/title/.yml +0 -731
  74. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_kirill_lyanoi_z_video2152699_168591741_2F56fd229a9dfe2dcdbe/view_count/.yml +0 -731
  75. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_kirill_lyanoi_z_video2152699_168591741_2F56fd229a9dfe2dcdbe/width/.yml +0 -728
  76. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video-54799401_165822734/title/.yml +0 -1226
  77. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/description/.yml +0 -997
  78. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/duration/.yml +0 -997
  79. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/embed_code/.yml +0 -997
  80. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/embed_url/.yml +0 -998
  81. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/height/.yml +0 -998
  82. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/keywords/.yml +0 -997
  83. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/title/.yml +0 -997
  84. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/view_count/.yml +0 -997
  85. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_video39576223_108370515/width/.yml +0 -998
  86. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_videos43640822_/video43640822_168790809/title/.yml +0 -597
  87. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/_available_/with_invalid_video/_available_/.yml +0 -69
  88. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/_available_/with_valid_video/_available_/.yml +0 -71
  89. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_duration/.yml +0 -78
  90. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_height/.yml +0 -78
  91. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_thumbnail_large/.yml +0 -78
  92. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_thumbnail_medium/.yml +0 -78
  93. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_thumbnail_small/.yml +0 -78
  94. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_title/.yml +0 -78
  95. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_width/.yml +0 -78
  96. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_duration/.yml +0 -78
  97. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_height/.yml +0 -78
  98. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_thumbnail_large/.yml +0 -78
  99. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_thumbnail_medium/.yml +0 -78
  100. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_thumbnail_small/.yml +0 -78
  101. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_title/.yml +0 -78
  102. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_width/.yml +0 -78
  103. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_valid_video/_available_/.yml +0 -56
  104. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_video_is_unavailable_video/_available_/.yml +0 -46
  105. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_video_no_longer_available_due_to_a_copyright_claim_video/_available_/.yml +0 -46
  106. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_date/.yml +0 -61
  107. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_description/.yml +0 -63
  108. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_duration/.yml +0 -63
  109. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_keywords/.yml +0 -63
  110. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_thumbnail_large/.yml +0 -61
  111. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_thumbnail_medium/.yml +0 -61
  112. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_thumbnail_small/.yml +0 -61
  113. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_title/.yml +0 -63
  114. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_view_count/.yml +0 -61
  115. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/_available_/with_invalid_playlist/_available_/.yml +0 -46
  116. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/_available_/with_valid_playlist/_available_/.yml +0 -56
  117. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL0E8117603D70E10A_in_embed_path/_videos/.yml +0 -61
  118. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_description/.yml +0 -96
  119. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_thumbnail_large/.yml +0 -96
  120. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_thumbnail_medium/.yml +0 -96
  121. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_thumbnail_small/.yml +0 -96
  122. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_title/.yml +0 -98
  123. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_videos/.yml +0 -96
@@ -1,43 +1,51 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe VideoInfo::Providers::Vimeo do
4
+ before(:all) do
5
+ VideoInfo.provider_api_keys = { vimeo: '6b66b015a3504793b4f541d878f46ff6' }
6
+ end
4
7
 
5
- describe ".usable?" do
8
+ describe '.usable?' do
6
9
  subject { VideoInfo::Providers::Vimeo.usable?(url) }
7
10
 
8
- context "with vimeo url" do
11
+ context 'with vimeo url' do
9
12
  let(:url) { 'http://www.vimeo.com/898029' }
10
13
  it { is_expected.to be_truthy }
11
14
  end
12
15
 
13
- context "with Vimeo OnDemand url" do
16
+ context 'with Vimeo OnDemand url' do
14
17
  let(:url) { 'https://vimeo.com/ondemand/less/101677664' }
15
18
  it { is_expected.to be_truthy }
16
19
  end
17
20
 
18
- context "with Vimeo Channels url" do
21
+ context 'with Vimeo Channels url' do
19
22
  let(:url) { 'https://vimeo.com/channels/any_channel/111431415' }
20
23
  it { is_expected.to be_truthy }
21
24
  end
22
25
 
23
- context "with vimeo album url" do
26
+ context "with Vimeo Review url" do
27
+ let(:url) { 'https://vimeo.com/user39798190/review/126641548/8a56234e32' }
28
+ it { is_expected.to be_truthy }
29
+ end
30
+
31
+ context 'with vimeo album url' do
24
32
  let(:url) { 'http://vimeo.com/album/2755718' }
25
33
  it { is_expected.to be_falsey }
26
34
  end
27
35
 
28
- context "with vimeo hubnub embed url" do
36
+ context 'with vimeo hubnub embed url' do
29
37
  let(:url) { 'http://player.vimeo.com/hubnut/album/2755718' }
30
38
  it { is_expected.to be_falsey }
31
39
  end
32
40
 
33
- context "with other url" do
41
+ context 'with other url' do
34
42
  let(:url) { 'http://www.youtube.com/898029' }
35
43
  it { is_expected.to be_falsey }
36
44
  end
37
45
  end
38
46
 
39
- describe "#available?" do
40
- context "with valid video", :vcr do
47
+ describe '#available?' do
48
+ context 'with valid video', :vcr do
41
49
  subject { VideoInfo.new('http://www.vimeo.com/898029') }
42
50
 
43
51
  describe '#available?' do
@@ -62,7 +70,7 @@ describe VideoInfo::Providers::Vimeo do
62
70
  end
63
71
  end
64
72
 
65
- context "with video 898029", :vcr do
73
+ context 'with video 898029', :vcr do
66
74
  subject { VideoInfo.new('http://www.vimeo.com/898029') }
67
75
 
68
76
  describe '#provider' do
@@ -122,22 +130,32 @@ describe VideoInfo::Providers::Vimeo do
122
130
 
123
131
  describe '#date' do
124
132
  subject { super().date }
125
- it { is_expected.to eq Time.parse('2008-04-14 13:10:39', Time.now.utc) }
133
+ it { is_expected.to eq Time.parse('2008-04-14T17:10:39+00:00', Time.now.utc).utc }
126
134
  end
127
135
 
128
136
  describe '#thumbnail_small' do
129
137
  subject { super().thumbnail_small }
130
- it { is_expected.to eq 'http://i.vimeocdn.com/video/34373130_100x75.jpg' }
138
+ it { is_expected.to eq 'https://i.vimeocdn.com/video/34373130_100x75.jpg' }
131
139
  end
132
140
 
133
141
  describe '#thumbnail_medium' do
134
142
  subject { super().thumbnail_medium }
135
- it { is_expected.to eq 'http://i.vimeocdn.com/video/34373130_200x150.jpg' }
143
+ it { is_expected.to eq 'https://i.vimeocdn.com/video/34373130_200x150.jpg' }
136
144
  end
137
145
 
138
146
  describe '#thumbnail_large' do
139
147
  subject { super().thumbnail_large }
140
- it { is_expected.to eq 'http://i.vimeocdn.com/video/34373130_640.jpg' }
148
+ it { is_expected.to eq 'https://i.vimeocdn.com/video/34373130_640.jpg' }
149
+ end
150
+
151
+ describe '#author_thumbnail' do
152
+ subject { super().author_thumbnail }
153
+ it { is_expected.to eq 'https://i.vimeocdn.com/portrait/2577152_75x75.jpg' }
154
+ end
155
+
156
+ describe '#author' do
157
+ subject { super().author }
158
+ it { is_expected.to eq 'Octave Zangs' }
141
159
  end
142
160
 
143
161
  describe '#view_count' do
@@ -146,20 +164,20 @@ describe VideoInfo::Providers::Vimeo do
146
164
  end
147
165
  end
148
166
 
149
- context "with video 898029 and url_attributes", :vcr do
167
+ context 'with video 898029 and url_attributes', :vcr do
150
168
  subject { VideoInfo.new('http://www.vimeo.com/898029') }
151
169
 
152
170
  it { expect(subject.embed_code(url_attributes: { autoplay: 1 })).to match(/autoplay=1/) }
153
171
  end
154
172
 
155
- context "with video 898029 and iframe_attributes", :vcr do
173
+ context 'with video 898029 and iframe_attributes', :vcr do
156
174
  subject { VideoInfo.new('http://www.vimeo.com/898029') }
157
175
 
158
176
  it { expect(subject.embed_code(iframe_attributes: { width: 800, height: 600 })).to match(/width="800"/) }
159
177
  it { expect(subject.embed_code(iframe_attributes: { width: 800, height: 600 })).to match(/height="600"/) }
160
178
  end
161
179
 
162
- context "with video 898029 in /group/ url", :vcr do
180
+ context 'with video 898029 in /group/ url', :vcr do
163
181
  subject { VideoInfo.new('http://vimeo.com/groups/1234/videos/898029') }
164
182
 
165
183
  describe '#provider' do
@@ -173,7 +191,7 @@ describe VideoInfo::Providers::Vimeo do
173
191
  end
174
192
  end
175
193
 
176
- context "with video 898029 in /group/ url", :vcr do
194
+ context 'with video 898029 in /group/ url', :vcr do
177
195
  subject { VideoInfo.new('http://player.vimeo.com/video/898029') }
178
196
 
179
197
  describe '#provider' do
@@ -187,7 +205,7 @@ describe VideoInfo::Providers::Vimeo do
187
205
  end
188
206
  end
189
207
 
190
- context "with video 898029 in text", :vcr do
208
+ context 'with video 898029 in text', :vcr do
191
209
  subject { VideoInfo.new('<a href="http://www.vimeo.com/898029">http://www.vimeo.com/898029</a>') }
192
210
 
193
211
  describe '#provider' do
@@ -201,18 +219,24 @@ describe VideoInfo::Providers::Vimeo do
201
219
  end
202
220
  end
203
221
 
204
- context "with video 101677664 in /ondemand/ url", :vcr do
222
+ context 'with video 101677664 in /ondemand/ url', :vcr do
205
223
  subject { VideoInfo.new('https://vimeo.com/ondemand/less/101677664') }
206
224
 
207
225
  its(:provider) { should eq 'Vimeo' }
208
226
  its(:video_id) { should eq '101677664' }
209
227
  end
210
228
 
211
- context "with video 111431415 in /channels/*/ url", :vcr do
229
+ context 'with video 111431415 in /channels/*/ url', :vcr do
212
230
  subject { VideoInfo.new('https://vimeo.com/channels/some_channel1/111431415') }
213
231
 
214
232
  its(:provider) { should eq 'Vimeo' }
215
233
  its(:video_id) { should eq '111431415' }
216
234
  end
217
235
 
236
+ context "with video 126641548 in /user*/review/126641548/* url", :vcr do
237
+ subject { VideoInfo.new('http://www.vimeo.com/user39798190/review/126641548/8a56234e32') }
238
+
239
+ its(:provider) { should eq 'Vimeo' }
240
+ its(:video_id) { should eq '126641548' }
241
+ end
218
242
  end
@@ -56,7 +56,7 @@ describe VideoInfo::Providers::Vkontakte do
56
56
  end
57
57
 
58
58
  context "with private video", :vcr do
59
- subject { VideoInfo.new('http://vk.com/video9491528_165193133') }
59
+ subject { VideoInfo.new('http://vk.com/video39576223_166315543') }
60
60
  its(:available?) { should be_falsey }
61
61
  end
62
62
 
@@ -131,4 +131,4 @@ describe VideoInfo::Providers::Vkontakte do
131
131
  its(:title) { should eq 'SpaceGlasses are the future of computing' }
132
132
  end
133
133
 
134
- end
134
+ end
@@ -0,0 +1,392 @@
1
+ require 'spec_helper'
2
+
3
+ describe VideoInfo::Providers::Youtube do
4
+ before(:all) do
5
+ VideoInfo.provider_api_keys = { youtube: 'AIzaSyA6PYwSr1EnLFUFy1cZDk3Ifb0rxeJaeZ0' }
6
+ end
7
+
8
+ describe ".usable?" do
9
+ subject { VideoInfo::Providers::Youtube.usable?(url) }
10
+
11
+ context "with youtube.com url" do
12
+ let(:url) { 'http://www.youtube.com/watch?v=Xp6CXF' }
13
+ it { is_expected.to be_truthy }
14
+ end
15
+
16
+ context "with youtu.be url" do
17
+ let(:url) { 'http://youtu.be/JM9NgvjjVng' }
18
+ it { is_expected.to be_truthy }
19
+ end
20
+
21
+ context "with other url" do
22
+ let(:url) { 'http://google.com/video1' }
23
+ it { is_expected.to be_falsey }
24
+ end
25
+
26
+ context "with playlist url" do
27
+ let(:url) { 'http://www.youtube.com/playlist?p=PLA575C81A1FBC04CF' }
28
+ it { is_expected.to be_falsey }
29
+ end
30
+ end
31
+
32
+ describe "#available?" do
33
+ context "with valid video", :vcr do
34
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
35
+
36
+ describe '#available?' do
37
+ subject { super().available? }
38
+ it { is_expected.to be_truthy }
39
+ end
40
+ end
41
+
42
+ context "with 'video is unavailable' video", :vcr do
43
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=SUkXvWn1m7Q') }
44
+
45
+ describe '#available?' do
46
+ subject { super().available? }
47
+ it { is_expected.to be_falsey }
48
+ end
49
+
50
+ describe '#provider' do
51
+ subject { super().provider }
52
+ it { is_expected.to eq 'YouTube' }
53
+ end
54
+
55
+ describe '#video_id' do
56
+ subject { super().video_id }
57
+ it { is_expected.to eq 'SUkXvWn1m7Q' }
58
+ end
59
+
60
+ describe '#url' do
61
+ subject { super().url }
62
+ it { is_expected.to eq 'http://www.youtube.com/watch?v=SUkXvWn1m7Q' }
63
+ end
64
+
65
+ describe '#embed_url' do
66
+ subject { super().embed_url }
67
+ it { is_expected.to eq '//www.youtube.com/embed/SUkXvWn1m7Q' }
68
+ end
69
+
70
+ describe '#embed_code' do
71
+ subject { super().embed_code }
72
+ it { is_expected.to eq '<iframe src="//www.youtube.com/embed/SUkXvWn1m7Q" frameborder="0" allowfullscreen="allowfullscreen"></iframe>' }
73
+ end
74
+
75
+ describe '#title' do
76
+ subject { super().title }
77
+ it { is_expected.to eq nil }
78
+ end
79
+
80
+ describe '#description' do
81
+ subject { super().description }
82
+ it { is_expected.to eq nil }
83
+ end
84
+
85
+ describe '#keywords' do
86
+ subject { super().keywords }
87
+ it { is_expected.to be_nil }
88
+ end
89
+
90
+ describe '#duration' do
91
+ subject { super().duration }
92
+ it { is_expected.to eq 0 }
93
+ end
94
+
95
+ describe '#date' do
96
+ subject { super().date }
97
+ it { is_expected.to eq nil }
98
+ end
99
+
100
+ describe '#thumbnail_small' do
101
+ subject { super().thumbnail_small }
102
+ it { is_expected.to eq 'https://i.ytimg.com/vi/SUkXvWn1m7Q/default.jpg' }
103
+ end
104
+
105
+ describe '#thumbnail_medium' do
106
+ subject { super().thumbnail_medium }
107
+ it { is_expected.to eq 'https://i.ytimg.com/vi/SUkXvWn1m7Q/mqdefault.jpg' }
108
+ end
109
+
110
+ describe '#thumbnail_large' do
111
+ subject { super().thumbnail_large }
112
+ it { is_expected.to eq 'https://i.ytimg.com/vi/SUkXvWn1m7Q/hqdefault.jpg' }
113
+ end
114
+
115
+ describe '#view_count' do
116
+ subject { super().view_count }
117
+ it { is_expected.to be == 0 }
118
+ end
119
+ end
120
+
121
+ context "with 'video no longer available due to a copyright claim' video", :vcr do
122
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=ffClNhwx0KU') }
123
+
124
+ describe '#available?' do
125
+ subject { super().available? }
126
+ it { is_expected.to be_truthy }
127
+ end
128
+ end
129
+ end
130
+
131
+ context "with video mZqGqE0D0n4", :vcr do
132
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
133
+
134
+ describe '#provider' do
135
+ subject { super().provider }
136
+ it { is_expected.to eq 'YouTube' }
137
+ end
138
+
139
+ describe '#video_id' do
140
+ subject { super().video_id }
141
+ it { is_expected.to eq 'mZqGqE0D0n4' }
142
+ end
143
+
144
+ describe '#url' do
145
+ subject { super().url }
146
+ it { is_expected.to eq 'http://www.youtube.com/watch?v=mZqGqE0D0n4' }
147
+ end
148
+
149
+ describe '#embed_url' do
150
+ subject { super().embed_url }
151
+ it { is_expected.to eq '//www.youtube.com/embed/mZqGqE0D0n4' }
152
+ end
153
+
154
+ describe '#embed_code' do
155
+ subject { super().embed_code }
156
+ it { is_expected.to eq '<iframe src="//www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen"></iframe>' }
157
+ end
158
+
159
+ describe '#title' do
160
+ subject { super().title }
161
+ it { is_expected.to eq 'Cherry Bloom - King Of The Knife' }
162
+ end
163
+
164
+ describe '#description' do
165
+ subject { super().description }
166
+ it { is_expected.to eq 'The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net' }
167
+ end
168
+
169
+ describe '#keywords' do
170
+ subject { super().keywords }
171
+ it { is_expected.to eq %w(cherry bloom king of the knife guitar drum clip rock alternative tremplin Paris-Forum) }
172
+ end
173
+
174
+ describe '#duration' do
175
+ subject { super().duration }
176
+ it { is_expected.to eq 176 }
177
+ end
178
+
179
+ describe '#width' do
180
+ subject { super().width }
181
+ it { is_expected.to be_nil }
182
+ end
183
+
184
+ describe '#height' do
185
+ subject { super().height }
186
+ it { is_expected.to be_nil }
187
+ end
188
+
189
+ describe '#date' do
190
+ subject { super().date }
191
+ it { is_expected.to eq Time.parse('Sat Apr 12 22:25:35 UTC 2008', Time.now.utc) }
192
+ end
193
+
194
+ describe '#thumbnail_small' do
195
+ subject { super().thumbnail_small }
196
+ it { is_expected.to eq 'https://i.ytimg.com/vi/mZqGqE0D0n4/default.jpg' }
197
+ end
198
+
199
+ describe '#thumbnail_medium' do
200
+ subject { super().thumbnail_medium }
201
+ it { is_expected.to eq 'https://i.ytimg.com/vi/mZqGqE0D0n4/mqdefault.jpg' }
202
+ end
203
+
204
+ describe '#thumbnail_large' do
205
+ subject { super().thumbnail_large }
206
+ it { is_expected.to eq 'https://i.ytimg.com/vi/mZqGqE0D0n4/hqdefault.jpg' }
207
+ end
208
+
209
+ describe '#view_count' do
210
+ subject { super().view_count }
211
+ it { is_expected.to be > 4000 }
212
+ end
213
+ end
214
+
215
+ context "with video oQ49W_xKzKA", :vcr do
216
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=oQ49W_xKzKA') }
217
+
218
+ it { expect(subject.embed_code(url_attributes: { autoplay: 1 })).to match(/autoplay=1/) }
219
+ end
220
+
221
+ context "with video oQ49W_xKzKA", :vcr do
222
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=oQ49W_xKzKA') }
223
+
224
+ describe '#provider' do
225
+ subject { super().provider }
226
+ it { is_expected.to eq 'YouTube' }
227
+ end
228
+
229
+ describe '#video_id' do
230
+ subject { super().video_id }
231
+ it { is_expected.to eq 'oQ49W_xKzKA' }
232
+ end
233
+ end
234
+
235
+ context "with video Xp6CXF-Cesg", :vcr do
236
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=Xp6CXF-Cesg') }
237
+
238
+ describe '#provider' do
239
+ subject { super().provider }
240
+ it { is_expected.to eq 'YouTube' }
241
+ end
242
+
243
+ describe '#video_id' do
244
+ subject { super().video_id }
245
+ it { is_expected.to eq 'Xp6CXF-Cesg' }
246
+ end
247
+ end
248
+
249
+ context "with video VeasFckfMHY in user url", :vcr do
250
+ subject { VideoInfo.new('http://www.youtube.com/user/EducatorVids3?v=VeasFckfMHY') }
251
+
252
+ describe '#provider' do
253
+ subject { super().provider }
254
+ it { is_expected.to eq 'YouTube' }
255
+ end
256
+
257
+ describe '#video_id' do
258
+ subject { super().video_id }
259
+ it { is_expected.to eq 'VeasFckfMHY' }
260
+ end
261
+
262
+ describe '#url' do
263
+ subject { super().url }
264
+ it { is_expected.to eq 'http://www.youtube.com/user/EducatorVids3?v=VeasFckfMHY' }
265
+ end
266
+ end
267
+
268
+ context "with video VeasFckfMHY after params", :vcr do
269
+ subject { VideoInfo.new('http://www.youtube.com/watch?feature=player_profilepage&v=VeasFckfMHY') }
270
+
271
+ describe '#provider' do
272
+ subject { super().provider }
273
+ it { is_expected.to eq 'YouTube' }
274
+ end
275
+
276
+ describe '#video_id' do
277
+ subject { super().video_id }
278
+ it { is_expected.to eq 'VeasFckfMHY' }
279
+ end
280
+
281
+ describe '#url' do
282
+ subject { super().url }
283
+ it { is_expected.to eq 'http://www.youtube.com/watch?feature=player_profilepage&v=VeasFckfMHY' }
284
+ end
285
+ end
286
+
287
+ context "with video VeasFckfMHY in path", :vcr do
288
+ subject { VideoInfo.new('http://www.youtube.com/v/VeasFckfMHY') }
289
+
290
+ describe '#provider' do
291
+ subject { super().provider }
292
+ it { is_expected.to eq 'YouTube' }
293
+ end
294
+
295
+ describe '#video_id' do
296
+ subject { super().video_id }
297
+ it { is_expected.to eq 'VeasFckfMHY' }
298
+ end
299
+ end
300
+
301
+ context "with video VeasFckfMHY in e path", :vcr do
302
+ subject { VideoInfo.new('http://www.youtube.com/e/VeasFckfMHY') }
303
+
304
+ describe '#provider' do
305
+ subject { super().provider }
306
+ it { is_expected.to eq 'YouTube' }
307
+ end
308
+
309
+ describe '#video_id' do
310
+ subject { super().video_id }
311
+ it { is_expected.to eq 'VeasFckfMHY' }
312
+ end
313
+ end
314
+
315
+ context "with video VeasFckfMHY in embed path", :vcr do
316
+ subject { VideoInfo.new('http://www.youtube.com/embed/VeasFckfMHY') }
317
+
318
+ describe '#provider' do
319
+ subject { super().provider }
320
+ it { is_expected.to eq 'YouTube' }
321
+ end
322
+
323
+ describe '#video_id' do
324
+ subject { super().video_id }
325
+ it { is_expected.to eq 'VeasFckfMHY' }
326
+ end
327
+ end
328
+
329
+ context "with video JM9NgvjjVng in youtu.be url", :vcr do
330
+ subject { VideoInfo.new('http://youtu.be/JM9NgvjjVng') }
331
+
332
+ describe '#provider' do
333
+ subject { super().provider }
334
+ it { is_expected.to eq 'YouTube' }
335
+ end
336
+
337
+ describe '#video_id' do
338
+ subject { super().video_id }
339
+ it { is_expected.to eq 'JM9NgvjjVng' }
340
+ end
341
+ end
342
+
343
+ context 'without http or www', :vcr do
344
+ subject { VideoInfo.new('youtu.be/JM9NgvjjVng') }
345
+
346
+ describe '#provider' do
347
+ subject { super().provider }
348
+ it { is_expected.to eq('YouTube') }
349
+ end
350
+
351
+ describe '#video_id' do
352
+ subject { super().video_id }
353
+ it { is_expected.to eq 'JM9NgvjjVng' }
354
+ end
355
+ end
356
+
357
+ context "with video url in text", :vcr do
358
+ subject { VideoInfo.new('<a href="http://www.youtube.com/watch?v=mZqGqE0D0n4">http://www.youtube.com/watch?v=mZqGqE0D0n4</a>') }
359
+
360
+ describe '#provider' do
361
+ subject { super().provider }
362
+ it { is_expected.to eq('YouTube') }
363
+ end
364
+
365
+ describe '#video_id' do
366
+ subject { super().video_id }
367
+ it { is_expected.to eq('mZqGqE0D0n4') }
368
+ end
369
+ end
370
+
371
+ context "with iframe attributes", :vcr do
372
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
373
+
374
+ describe '#provider' do
375
+ subject { super().provider }
376
+ it { is_expected.to eq('YouTube') }
377
+ end
378
+ it { expect(subject.embed_code(iframe_attributes: { width: 800, height: 600 })).to match(/width="800"/) }
379
+ it { expect(subject.embed_code(iframe_attributes: { width: 800, height: 600 })).to match(/height="600"/) }
380
+ end
381
+
382
+ context "with arbitrary iframe_attributes", :vcr do
383
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
384
+
385
+ describe '#provider' do
386
+ subject { super().provider }
387
+ it { is_expected.to eq('YouTube') }
388
+ end
389
+ it { expect(subject.embed_code(iframe_attributes: { :'data-colorbox' => true })).to match(/data-colorbox="true"/) }
390
+ end
391
+
392
+ end