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