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