]> jfr.im git - yt-dlp.git/blob - test/test_playlists.py
release 2014.08.24.5
[yt-dlp.git] / test / test_playlists.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3
4 ## DEPRECATED FILE!
5 # Add new tests to the extractors themselves, like this:
6 # _TEST = {
7 # 'url': 'http://example.com/playlist/42',
8 # 'playlist_mincount': 99,
9 # 'info_dict': {
10 # 'id': '42',
11 # 'title': 'Playlist number forty-two',
12 # }
13 # }
14
15 from __future__ import unicode_literals
16
17 # Allow direct execution
18 import os
19 import sys
20 import unittest
21 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
22
23 from test.helper import (
24 assertRegexpMatches,
25 assertGreaterEqual,
26 expect_info_dict,
27 FakeYDL,
28 )
29
30 from youtube_dl.extractor import (
31 AcademicEarthCourseIE,
32 DailymotionPlaylistIE,
33 DailymotionUserIE,
34 VimeoChannelIE,
35 VimeoUserIE,
36 VimeoAlbumIE,
37 VimeoGroupsIE,
38 VineUserIE,
39 UstreamChannelIE,
40 SoundcloudSetIE,
41 SoundcloudUserIE,
42 SoundcloudPlaylistIE,
43 TeacherTubeUserIE,
44 LivestreamIE,
45 LivestreamOriginalIE,
46 NHLVideocenterIE,
47 BambuserChannelIE,
48 BandcampAlbumIE,
49 SmotriCommunityIE,
50 SmotriUserIE,
51 IviCompilationIE,
52 ImdbListIE,
53 KhanAcademyIE,
54 EveryonesMixtapeIE,
55 RutubeChannelIE,
56 RutubePersonIE,
57 GoogleSearchIE,
58 GenericIE,
59 TEDIE,
60 ToypicsUserIE,
61 XTubeUserIE,
62 InstagramUserIE,
63 CSpanIE,
64 AolIE,
65 )
66
67
68 class TestPlaylists(unittest.TestCase):
69 def assertIsPlaylist(self, info):
70 """Make sure the info has '_type' set to 'playlist'"""
71 self.assertEqual(info['_type'], 'playlist')
72
73 def test_dailymotion_playlist(self):
74 dl = FakeYDL()
75 ie = DailymotionPlaylistIE(dl)
76 result = ie.extract('http://www.dailymotion.com/playlist/xv4bw_nqtv_sport/1#video=xl8v3q')
77 self.assertIsPlaylist(result)
78 self.assertEqual(result['title'], 'SPORT')
79 self.assertTrue(len(result['entries']) > 20)
80
81 def test_dailymotion_user(self):
82 dl = FakeYDL()
83 ie = DailymotionUserIE(dl)
84 result = ie.extract('https://www.dailymotion.com/user/nqtv')
85 self.assertIsPlaylist(result)
86 assertGreaterEqual(self, len(result['entries']), 100)
87 self.assertEqual(result['title'], 'Rémi Gaillard')
88
89 def test_vimeo_channel(self):
90 dl = FakeYDL()
91 ie = VimeoChannelIE(dl)
92 result = ie.extract('http://vimeo.com/channels/tributes')
93 self.assertIsPlaylist(result)
94 self.assertEqual(result['title'], 'Vimeo Tributes')
95 self.assertTrue(len(result['entries']) > 24)
96
97 def test_vimeo_user(self):
98 dl = FakeYDL()
99 ie = VimeoUserIE(dl)
100 result = ie.extract('http://vimeo.com/nkistudio/videos')
101 self.assertIsPlaylist(result)
102 self.assertEqual(result['title'], 'Nki')
103 self.assertTrue(len(result['entries']) > 65)
104
105 def test_vimeo_album(self):
106 dl = FakeYDL()
107 ie = VimeoAlbumIE(dl)
108 result = ie.extract('http://vimeo.com/album/2632481')
109 self.assertIsPlaylist(result)
110 self.assertEqual(result['title'], 'Staff Favorites: November 2013')
111 self.assertTrue(len(result['entries']) > 12)
112
113 def test_vimeo_groups(self):
114 dl = FakeYDL()
115 ie = VimeoGroupsIE(dl)
116 result = ie.extract('http://vimeo.com/groups/rolexawards')
117 self.assertIsPlaylist(result)
118 self.assertEqual(result['title'], 'Rolex Awards for Enterprise')
119 self.assertTrue(len(result['entries']) > 72)
120
121 def test_vine_user(self):
122 dl = FakeYDL()
123 ie = VineUserIE(dl)
124 result = ie.extract('https://vine.co/Visa')
125 self.assertIsPlaylist(result)
126 assertGreaterEqual(self, len(result['entries']), 47)
127
128 def test_ustream_channel(self):
129 dl = FakeYDL()
130 ie = UstreamChannelIE(dl)
131 result = ie.extract('http://www.ustream.tv/channel/channeljapan')
132 self.assertIsPlaylist(result)
133 self.assertEqual(result['id'], '10874166')
134 assertGreaterEqual(self, len(result['entries']), 54)
135
136 def test_soundcloud_set(self):
137 dl = FakeYDL()
138 ie = SoundcloudSetIE(dl)
139 result = ie.extract('https://soundcloud.com/the-concept-band/sets/the-royal-concept-ep')
140 self.assertIsPlaylist(result)
141 self.assertEqual(result['title'], 'The Royal Concept EP')
142 assertGreaterEqual(self, len(result['entries']), 6)
143
144 def test_soundcloud_user(self):
145 dl = FakeYDL()
146 ie = SoundcloudUserIE(dl)
147 result = ie.extract('https://soundcloud.com/the-concept-band')
148 self.assertIsPlaylist(result)
149 self.assertEqual(result['id'], '9615865')
150 assertGreaterEqual(self, len(result['entries']), 12)
151
152 def test_soundcloud_likes(self):
153 dl = FakeYDL()
154 ie = SoundcloudUserIE(dl)
155 result = ie.extract('https://soundcloud.com/the-concept-band/likes')
156 self.assertIsPlaylist(result)
157 self.assertEqual(result['id'], '9615865')
158 assertGreaterEqual(self, len(result['entries']), 1)
159
160 def test_soundcloud_playlist(self):
161 dl = FakeYDL()
162 ie = SoundcloudPlaylistIE(dl)
163 result = ie.extract('http://api.soundcloud.com/playlists/4110309')
164 self.assertIsPlaylist(result)
165 self.assertEqual(result['id'], '4110309')
166 self.assertEqual(result['title'], 'TILT Brass - Bowery Poetry Club, August \'03 [Non-Site SCR 02]')
167 assertRegexpMatches(
168 self, result['description'], r'.*?TILT Brass - Bowery Poetry Club')
169 self.assertEqual(len(result['entries']), 6)
170
171 def test_livestream_event(self):
172 dl = FakeYDL()
173 ie = LivestreamIE(dl)
174 result = ie.extract('http://new.livestream.com/tedx/cityenglish')
175 self.assertIsPlaylist(result)
176 self.assertEqual(result['title'], 'TEDCity2.0 (English)')
177 assertGreaterEqual(self, len(result['entries']), 4)
178
179 def test_livestreamoriginal_folder(self):
180 dl = FakeYDL()
181 ie = LivestreamOriginalIE(dl)
182 result = ie.extract('https://www.livestream.com/newplay/folder?dirId=a07bf706-d0e4-4e75-a747-b021d84f2fd3')
183 self.assertIsPlaylist(result)
184 self.assertEqual(result['id'], 'a07bf706-d0e4-4e75-a747-b021d84f2fd3')
185 assertGreaterEqual(self, len(result['entries']), 28)
186
187 def test_nhl_videocenter(self):
188 dl = FakeYDL()
189 ie = NHLVideocenterIE(dl)
190 result = ie.extract('http://video.canucks.nhl.com/videocenter/console?catid=999')
191 self.assertIsPlaylist(result)
192 self.assertEqual(result['id'], '999')
193 self.assertEqual(result['title'], 'Highlights')
194 self.assertEqual(len(result['entries']), 12)
195
196 def test_bambuser_channel(self):
197 dl = FakeYDL()
198 ie = BambuserChannelIE(dl)
199 result = ie.extract('http://bambuser.com/channel/pixelversity')
200 self.assertIsPlaylist(result)
201 self.assertEqual(result['title'], 'pixelversity')
202 assertGreaterEqual(self, len(result['entries']), 60)
203
204 def test_bandcamp_album(self):
205 dl = FakeYDL()
206 ie = BandcampAlbumIE(dl)
207 result = ie.extract('http://nightbringer.bandcamp.com/album/hierophany-of-the-open-grave')
208 self.assertIsPlaylist(result)
209 self.assertEqual(result['title'], 'Hierophany of the Open Grave')
210 assertGreaterEqual(self, len(result['entries']), 9)
211
212 def test_smotri_community(self):
213 dl = FakeYDL()
214 ie = SmotriCommunityIE(dl)
215 result = ie.extract('http://smotri.com/community/video/kommuna')
216 self.assertIsPlaylist(result)
217 self.assertEqual(result['id'], 'kommuna')
218 self.assertEqual(result['title'], 'КПРФ')
219 assertGreaterEqual(self, len(result['entries']), 4)
220
221 def test_smotri_user(self):
222 dl = FakeYDL()
223 ie = SmotriUserIE(dl)
224 result = ie.extract('http://smotri.com/user/inspector')
225 self.assertIsPlaylist(result)
226 self.assertEqual(result['id'], 'inspector')
227 self.assertEqual(result['title'], 'Inspector')
228 assertGreaterEqual(self, len(result['entries']), 9)
229
230 def test_AcademicEarthCourse(self):
231 dl = FakeYDL()
232 ie = AcademicEarthCourseIE(dl)
233 result = ie.extract('http://academicearth.org/playlists/laws-of-nature/')
234 self.assertIsPlaylist(result)
235 self.assertEqual(result['id'], 'laws-of-nature')
236 self.assertEqual(result['title'], 'Laws of Nature')
237 self.assertEqual(result['description'],u'Introduce yourself to the laws of nature with these free online college lectures from Yale, Harvard, and MIT.')# u"Today's websites are increasingly dynamic. Pages are no longer static HTML files but instead generated by scripts and database calls. User interfaces are more seamless, with technologies like Ajax replacing traditional page reloads. This course teaches students how to build dynamic websites with Ajax and with Linux, Apache, MySQL, and PHP (LAMP), one of today's most popular frameworks. Students learn how to set up domain names with DNS, how to structure pages with XHTML and CSS, how to program in JavaScript and PHP, how to configure Apache and MySQL, how to design and query databases with SQL, how to use Ajax with both XML and JSON, and how to build mashups. The course explores issues of security, scalability, and cross-browser support and also discusses enterprise-level deployments of websites, including third-party hosting, virtualization, colocation in data centers, firewalling, and load-balancing.")
238 self.assertEqual(len(result['entries']), 4)
239
240 def test_ivi_compilation(self):
241 dl = FakeYDL()
242 ie = IviCompilationIE(dl)
243 result = ie.extract('http://www.ivi.ru/watch/dvoe_iz_lartsa')
244 self.assertIsPlaylist(result)
245 self.assertEqual(result['id'], 'dvoe_iz_lartsa')
246 self.assertEqual(result['title'], 'Двое из ларца (2006 - 2008)')
247 assertGreaterEqual(self, len(result['entries']), 24)
248
249 def test_ivi_compilation_season(self):
250 dl = FakeYDL()
251 ie = IviCompilationIE(dl)
252 result = ie.extract('http://www.ivi.ru/watch/dvoe_iz_lartsa/season1')
253 self.assertIsPlaylist(result)
254 self.assertEqual(result['id'], 'dvoe_iz_lartsa/season1')
255 self.assertEqual(result['title'], 'Двое из ларца (2006 - 2008) 1 сезон')
256 assertGreaterEqual(self, len(result['entries']), 12)
257
258 def test_imdb_list(self):
259 dl = FakeYDL()
260 ie = ImdbListIE(dl)
261 result = ie.extract('http://www.imdb.com/list/JFs9NWw6XI0')
262 self.assertIsPlaylist(result)
263 self.assertEqual(result['id'], 'JFs9NWw6XI0')
264 self.assertEqual(result['title'], 'March 23, 2012 Releases')
265 self.assertEqual(len(result['entries']), 7)
266
267 def test_khanacademy_topic(self):
268 dl = FakeYDL()
269 ie = KhanAcademyIE(dl)
270 result = ie.extract('https://www.khanacademy.org/math/applied-math/cryptography')
271 self.assertIsPlaylist(result)
272 self.assertEqual(result['id'], 'cryptography')
273 self.assertEqual(result['title'], 'Journey into cryptography')
274 self.assertEqual(result['description'], 'How have humans protected their secret messages through history? What has changed today?')
275 assertGreaterEqual(self, len(result['entries']), 3)
276
277 def test_EveryonesMixtape(self):
278 dl = FakeYDL()
279 ie = EveryonesMixtapeIE(dl)
280 result = ie.extract('http://everyonesmixtape.com/#/mix/m7m0jJAbMQi')
281 self.assertIsPlaylist(result)
282 self.assertEqual(result['id'], 'm7m0jJAbMQi')
283 self.assertEqual(result['title'], 'Driving')
284 self.assertEqual(len(result['entries']), 24)
285
286 def test_rutube_channel(self):
287 dl = FakeYDL()
288 ie = RutubeChannelIE(dl)
289 result = ie.extract('http://rutube.ru/tags/video/1800/')
290 self.assertIsPlaylist(result)
291 self.assertEqual(result['id'], '1800')
292 assertGreaterEqual(self, len(result['entries']), 68)
293
294 def test_rutube_person(self):
295 dl = FakeYDL()
296 ie = RutubePersonIE(dl)
297 result = ie.extract('http://rutube.ru/video/person/313878/')
298 self.assertIsPlaylist(result)
299 self.assertEqual(result['id'], '313878')
300 assertGreaterEqual(self, len(result['entries']), 37)
301
302 def test_multiple_brightcove_videos(self):
303 # https://github.com/rg3/youtube-dl/issues/2283
304 dl = FakeYDL()
305 ie = GenericIE(dl)
306 result = ie.extract('http://www.newyorker.com/online/blogs/newsdesk/2014/01/always-never-nuclear-command-and-control.html')
307 self.assertIsPlaylist(result)
308 self.assertEqual(result['id'], 'always-never-nuclear-command-and-control')
309 self.assertEqual(result['title'], 'Always/Never: A Little-Seen Movie About Nuclear Command and Control : The New Yorker')
310 self.assertEqual(len(result['entries']), 3)
311
312 def test_GoogleSearch(self):
313 dl = FakeYDL()
314 ie = GoogleSearchIE(dl)
315 result = ie.extract('gvsearch15:python language')
316 self.assertIsPlaylist(result)
317 self.assertEqual(result['id'], 'python language')
318 self.assertEqual(result['title'], 'python language')
319 self.assertEqual(len(result['entries']), 15)
320
321 def test_generic_rss_feed(self):
322 dl = FakeYDL()
323 ie = GenericIE(dl)
324 result = ie.extract('http://phihag.de/2014/youtube-dl/rss.xml')
325 self.assertIsPlaylist(result)
326 self.assertEqual(result['id'], 'http://phihag.de/2014/youtube-dl/rss.xml')
327 self.assertEqual(result['title'], 'Zero Punctuation')
328 self.assertTrue(len(result['entries']) > 10)
329
330 def test_ted_playlist(self):
331 dl = FakeYDL()
332 ie = TEDIE(dl)
333 result = ie.extract('http://www.ted.com/playlists/who_are_the_hackers')
334 self.assertIsPlaylist(result)
335 self.assertEqual(result['id'], '10')
336 self.assertEqual(result['title'], 'Who are the hackers?')
337 assertGreaterEqual(self, len(result['entries']), 6)
338
339 def test_toypics_user(self):
340 dl = FakeYDL()
341 ie = ToypicsUserIE(dl)
342 result = ie.extract('http://videos.toypics.net/Mikey')
343 self.assertIsPlaylist(result)
344 self.assertEqual(result['id'], 'Mikey')
345 assertGreaterEqual(self, len(result['entries']), 17)
346
347 def test_xtube_user(self):
348 dl = FakeYDL()
349 ie = XTubeUserIE(dl)
350 result = ie.extract('http://www.xtube.com/community/profile.php?user=greenshowers')
351 self.assertIsPlaylist(result)
352 self.assertEqual(result['id'], 'greenshowers')
353 assertGreaterEqual(self, len(result['entries']), 155)
354
355 def test_InstagramUser(self):
356 dl = FakeYDL()
357 ie = InstagramUserIE(dl)
358 result = ie.extract('http://instagram.com/porsche')
359 self.assertIsPlaylist(result)
360 self.assertEqual(result['id'], 'porsche')
361 assertGreaterEqual(self, len(result['entries']), 2)
362 test_video = next(
363 e for e in result['entries']
364 if e['id'] == '614605558512799803_462752227')
365 dl.add_default_extra_info(test_video, ie, '(irrelevant URL)')
366 dl.process_video_result(test_video, download=False)
367 EXPECTED = {
368 'id': '614605558512799803_462752227',
369 'ext': 'mp4',
370 'title': '#Porsche Intelligent Performance.',
371 'thumbnail': 're:^https?://.*\.jpg',
372 'uploader': 'Porsche',
373 'uploader_id': 'porsche',
374 'timestamp': 1387486713,
375 'upload_date': '20131219',
376 }
377 expect_info_dict(self, EXPECTED, test_video)
378
379 def test_CSpan_playlist(self):
380 dl = FakeYDL()
381 ie = CSpanIE(dl)
382 result = ie.extract(
383 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall')
384 self.assertIsPlaylist(result)
385 self.assertEqual(result['id'], '342759')
386 self.assertEqual(
387 result['title'], 'General Motors Ignition Switch Recall')
388 whole_duration = sum(e['duration'] for e in result['entries'])
389 self.assertEqual(whole_duration, 14855)
390
391 def test_aol_playlist(self):
392 dl = FakeYDL()
393 ie = AolIE(dl)
394 result = ie.extract(
395 'http://on.aol.com/playlist/brace-yourself---todays-weirdest-news-152147?icid=OnHomepageC4_Omg_Img#_videoid=518184316')
396 self.assertIsPlaylist(result)
397 self.assertEqual(result['id'], '152147')
398 self.assertEqual(
399 result['title'], 'Brace Yourself - Today\'s Weirdest News')
400 assertGreaterEqual(self, len(result['entries']), 10)
401
402 def test_TeacherTubeUser(self):
403 dl = FakeYDL()
404 ie = TeacherTubeUserIE(dl)
405 result = ie.extract('http://www.teachertube.com/user/profile/rbhagwati2')
406 self.assertIsPlaylist(result)
407 self.assertEqual(result['id'], 'rbhagwati2')
408 assertGreaterEqual(self, len(result['entries']), 179)
409
410 if __name__ == '__main__':
411 unittest.main()