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