]> Raphaël G. Git Repositories - youtubedl/blob - test/test_playlists.py
Merge tag 'upstream/2014.07.11'
[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']) >= 50)
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_playlist(self):
141 dl = FakeYDL()
142 ie = SoundcloudPlaylistIE(dl)
143 result = ie.extract('http://api.soundcloud.com/playlists/4110309')
144 self.assertIsPlaylist(result)
145 self.assertEqual(result['id'], '4110309')
146 self.assertEqual(result['title'], 'TILT Brass - Bowery Poetry Club, August \'03 [Non-Site SCR 02]')
147 assertRegexpMatches(
148 self, result['description'], r'TILT Brass - Bowery Poetry Club')
149 self.assertEqual(len(result['entries']), 6)
150
151 def test_livestream_event(self):
152 dl = FakeYDL()
153 ie = LivestreamIE(dl)
154 result = ie.extract('http://new.livestream.com/tedx/cityenglish')
155 self.assertIsPlaylist(result)
156 self.assertEqual(result['title'], 'TEDCity2.0 (English)')
157 self.assertTrue(len(result['entries']) >= 4)
158
159 def test_livestreamoriginal_folder(self):
160 dl = FakeYDL()
161 ie = LivestreamOriginalIE(dl)
162 result = ie.extract('https://www.livestream.com/newplay/folder?dirId=a07bf706-d0e4-4e75-a747-b021d84f2fd3')
163 self.assertIsPlaylist(result)
164 self.assertEqual(result['id'], 'a07bf706-d0e4-4e75-a747-b021d84f2fd3')
165 self.assertTrue(len(result['entries']) >= 28)
166
167 def test_nhl_videocenter(self):
168 dl = FakeYDL()
169 ie = NHLVideocenterIE(dl)
170 result = ie.extract('http://video.canucks.nhl.com/videocenter/console?catid=999')
171 self.assertIsPlaylist(result)
172 self.assertEqual(result['id'], '999')
173 self.assertEqual(result['title'], 'Highlights')
174 self.assertEqual(len(result['entries']), 12)
175
176 def test_bambuser_channel(self):
177 dl = FakeYDL()
178 ie = BambuserChannelIE(dl)
179 result = ie.extract('http://bambuser.com/channel/pixelversity')
180 self.assertIsPlaylist(result)
181 self.assertEqual(result['title'], 'pixelversity')
182 self.assertTrue(len(result['entries']) >= 60)
183
184 def test_bandcamp_album(self):
185 dl = FakeYDL()
186 ie = BandcampAlbumIE(dl)
187 result = ie.extract('http://mpallante.bandcamp.com/album/nightmare-night-ep')
188 self.assertIsPlaylist(result)
189 self.assertEqual(result['title'], 'Nightmare Night EP')
190 self.assertTrue(len(result['entries']) >= 4)
191
192 def test_smotri_community(self):
193 dl = FakeYDL()
194 ie = SmotriCommunityIE(dl)
195 result = ie.extract('http://smotri.com/community/video/kommuna')
196 self.assertIsPlaylist(result)
197 self.assertEqual(result['id'], 'kommuna')
198 self.assertEqual(result['title'], 'КПРФ')
199 self.assertTrue(len(result['entries']) >= 4)
200
201 def test_smotri_user(self):
202 dl = FakeYDL()
203 ie = SmotriUserIE(dl)
204 result = ie.extract('http://smotri.com/user/inspector')
205 self.assertIsPlaylist(result)
206 self.assertEqual(result['id'], 'inspector')
207 self.assertEqual(result['title'], 'Inspector')
208 self.assertTrue(len(result['entries']) >= 9)
209
210 def test_AcademicEarthCourse(self):
211 dl = FakeYDL()
212 ie = AcademicEarthCourseIE(dl)
213 result = ie.extract('http://academicearth.org/playlists/laws-of-nature/')
214 self.assertIsPlaylist(result)
215 self.assertEqual(result['id'], 'laws-of-nature')
216 self.assertEqual(result['title'], 'Laws of Nature')
217 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.")
218 self.assertEqual(len(result['entries']), 4)
219
220 def test_ivi_compilation(self):
221 dl = FakeYDL()
222 ie = IviCompilationIE(dl)
223 result = ie.extract('http://www.ivi.ru/watch/dvoe_iz_lartsa')
224 self.assertIsPlaylist(result)
225 self.assertEqual(result['id'], 'dvoe_iz_lartsa')
226 self.assertEqual(result['title'], 'Двое из ларца (2006 - 2008)')
227 self.assertTrue(len(result['entries']) >= 24)
228
229 def test_ivi_compilation_season(self):
230 dl = FakeYDL()
231 ie = IviCompilationIE(dl)
232 result = ie.extract('http://www.ivi.ru/watch/dvoe_iz_lartsa/season1')
233 self.assertIsPlaylist(result)
234 self.assertEqual(result['id'], 'dvoe_iz_lartsa/season1')
235 self.assertEqual(result['title'], 'Двое из ларца (2006 - 2008) 1 сезон')
236 self.assertTrue(len(result['entries']) >= 12)
237
238 def test_imdb_list(self):
239 dl = FakeYDL()
240 ie = ImdbListIE(dl)
241 result = ie.extract('http://www.imdb.com/list/JFs9NWw6XI0')
242 self.assertIsPlaylist(result)
243 self.assertEqual(result['id'], 'JFs9NWw6XI0')
244 self.assertEqual(result['title'], 'March 23, 2012 Releases')
245 self.assertEqual(len(result['entries']), 7)
246
247 def test_khanacademy_topic(self):
248 dl = FakeYDL()
249 ie = KhanAcademyIE(dl)
250 result = ie.extract('https://www.khanacademy.org/math/applied-math/cryptography')
251 self.assertIsPlaylist(result)
252 self.assertEqual(result['id'], 'cryptography')
253 self.assertEqual(result['title'], 'Journey into cryptography')
254 self.assertEqual(result['description'], 'How have humans protected their secret messages through history? What has changed today?')
255 self.assertTrue(len(result['entries']) >= 3)
256
257 def test_EveryonesMixtape(self):
258 dl = FakeYDL()
259 ie = EveryonesMixtapeIE(dl)
260 result = ie.extract('http://everyonesmixtape.com/#/mix/m7m0jJAbMQi')
261 self.assertIsPlaylist(result)
262 self.assertEqual(result['id'], 'm7m0jJAbMQi')
263 self.assertEqual(result['title'], 'Driving')
264 self.assertEqual(len(result['entries']), 24)
265
266 def test_rutube_channel(self):
267 dl = FakeYDL()
268 ie = RutubeChannelIE(dl)
269 result = ie.extract('http://rutube.ru/tags/video/1800/')
270 self.assertIsPlaylist(result)
271 self.assertEqual(result['id'], '1800')
272 self.assertTrue(len(result['entries']) >= 68)
273
274 def test_rutube_person(self):
275 dl = FakeYDL()
276 ie = RutubePersonIE(dl)
277 result = ie.extract('http://rutube.ru/video/person/313878/')
278 self.assertIsPlaylist(result)
279 self.assertEqual(result['id'], '313878')
280 self.assertTrue(len(result['entries']) >= 37)
281
282 def test_multiple_brightcove_videos(self):
283 # https://github.com/rg3/youtube-dl/issues/2283
284 dl = FakeYDL()
285 ie = GenericIE(dl)
286 result = ie.extract('http://www.newyorker.com/online/blogs/newsdesk/2014/01/always-never-nuclear-command-and-control.html')
287 self.assertIsPlaylist(result)
288 self.assertEqual(result['id'], 'always-never-nuclear-command-and-control')
289 self.assertEqual(result['title'], 'Always/Never: A Little-Seen Movie About Nuclear Command and Control : The New Yorker')
290 self.assertEqual(len(result['entries']), 3)
291
292 def test_GoogleSearch(self):
293 dl = FakeYDL()
294 ie = GoogleSearchIE(dl)
295 result = ie.extract('gvsearch15:python language')
296 self.assertIsPlaylist(result)
297 self.assertEqual(result['id'], 'python language')
298 self.assertEqual(result['title'], 'python language')
299 self.assertEqual(len(result['entries']), 15)
300
301 def test_generic_rss_feed(self):
302 dl = FakeYDL()
303 ie = GenericIE(dl)
304 result = ie.extract('http://phihag.de/2014/youtube-dl/rss.xml')
305 self.assertIsPlaylist(result)
306 self.assertEqual(result['id'], 'http://phihag.de/2014/youtube-dl/rss.xml')
307 self.assertEqual(result['title'], 'Zero Punctuation')
308 self.assertTrue(len(result['entries']) > 10)
309
310 def test_ted_playlist(self):
311 dl = FakeYDL()
312 ie = TEDIE(dl)
313 result = ie.extract('http://www.ted.com/playlists/who_are_the_hackers')
314 self.assertIsPlaylist(result)
315 self.assertEqual(result['id'], '10')
316 self.assertEqual(result['title'], 'Who are the hackers?')
317 self.assertTrue(len(result['entries']) >= 6)
318
319 def test_toypics_user(self):
320 dl = FakeYDL()
321 ie = ToypicsUserIE(dl)
322 result = ie.extract('http://videos.toypics.net/Mikey')
323 self.assertIsPlaylist(result)
324 self.assertEqual(result['id'], 'Mikey')
325 self.assertTrue(len(result['entries']) >= 17)
326
327 def test_xtube_user(self):
328 dl = FakeYDL()
329 ie = XTubeUserIE(dl)
330 result = ie.extract('http://www.xtube.com/community/profile.php?user=greenshowers')
331 self.assertIsPlaylist(result)
332 self.assertEqual(result['id'], 'greenshowers')
333 self.assertTrue(len(result['entries']) >= 155)
334
335 def test_InstagramUser(self):
336 dl = FakeYDL()
337 ie = InstagramUserIE(dl)
338 result = ie.extract('http://instagram.com/porsche')
339 self.assertIsPlaylist(result)
340 self.assertEqual(result['id'], 'porsche')
341 self.assertTrue(len(result['entries']) >= 2)
342 test_video = next(
343 e for e in result['entries']
344 if e['id'] == '614605558512799803_462752227')
345 dl.add_default_extra_info(test_video, ie, '(irrelevant URL)')
346 dl.process_video_result(test_video, download=False)
347 EXPECTED = {
348 'id': '614605558512799803_462752227',
349 'ext': 'mp4',
350 'title': '#Porsche Intelligent Performance.',
351 'thumbnail': 're:^https?://.*\.jpg',
352 'uploader': 'Porsche',
353 'uploader_id': 'porsche',
354 'timestamp': 1387486713,
355 'upload_date': '20131219',
356 }
357 expect_info_dict(self, EXPECTED, test_video)
358
359 def test_CSpan_playlist(self):
360 dl = FakeYDL()
361 ie = CSpanIE(dl)
362 result = ie.extract(
363 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall')
364 self.assertIsPlaylist(result)
365 self.assertEqual(result['id'], '342759')
366 self.assertEqual(
367 result['title'], 'General Motors Ignition Switch Recall')
368 whole_duration = sum(e['duration'] for e in result['entries'])
369 self.assertEqual(whole_duration, 14855)
370
371 def test_aol_playlist(self):
372 dl = FakeYDL()
373 ie = AolIE(dl)
374 result = ie.extract(
375 'http://on.aol.com/playlist/brace-yourself---todays-weirdest-news-152147?icid=OnHomepageC4_Omg_Img#_videoid=518184316')
376 self.assertIsPlaylist(result)
377 self.assertEqual(result['id'], '152147')
378 self.assertEqual(
379 result['title'], 'Brace Yourself - Today\'s Weirdest News')
380 self.assertTrue(len(result['entries']) >= 10)
381
382 def test_TeacherTubeUser(self):
383 dl = FakeYDL()
384 ie = TeacherTubeUserIE(dl)
385 result = ie.extract('http://www.teachertube.com/user/profile/rbhagwati2')
386 self.assertIsPlaylist(result)
387 self.assertEqual(result['id'], 'rbhagwati2')
388 self.assertTrue(len(result['entries']) >= 179)
389
390 if __name__ == '__main__':
391 unittest.main()