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