[slutload] Add new extractor
[youtube-dl] / 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     UstreamChannelIE,
27     SoundcloudSetIE,
28     SoundcloudUserIE,
29     SoundcloudPlaylistIE,
30     LivestreamIE,
31     NHLVideocenterIE,
32     BambuserChannelIE,
33     BandcampAlbumIE,
34     SmotriCommunityIE,
35     SmotriUserIE,
36     IviCompilationIE,
37     ImdbListIE,
38     KhanAcademyIE,
39     EveryonesMixtapeIE,
40     RutubeChannelIE,
41     GoogleSearchIE,
42     GenericIE,
43     TEDIE,
44     ToypicsUserIE,
45     XTubeUserIE,
46     InstagramUserIE,
47     CSpanIE,
48     AolIE,
49 )
50
51
52 class TestPlaylists(unittest.TestCase):
53     def assertIsPlaylist(self, info):
54         """Make sure the info has '_type' set to 'playlist'"""
55         self.assertEqual(info['_type'], 'playlist')
56
57     def test_dailymotion_playlist(self):
58         dl = FakeYDL()
59         ie = DailymotionPlaylistIE(dl)
60         result = ie.extract('http://www.dailymotion.com/playlist/xv4bw_nqtv_sport/1#video=xl8v3q')
61         self.assertIsPlaylist(result)
62         self.assertEqual(result['title'], 'SPORT')
63         self.assertTrue(len(result['entries']) > 20)
64
65     def test_dailymotion_user(self):
66         dl = FakeYDL()
67         ie = DailymotionUserIE(dl)
68         result = ie.extract('https://www.dailymotion.com/user/nqtv')
69         self.assertIsPlaylist(result)
70         self.assertEqual(result['title'], 'Rémi Gaillard')
71         self.assertTrue(len(result['entries']) >= 100)
72
73     def test_vimeo_channel(self):
74         dl = FakeYDL()
75         ie = VimeoChannelIE(dl)
76         result = ie.extract('http://vimeo.com/channels/tributes')
77         self.assertIsPlaylist(result)
78         self.assertEqual(result['title'], 'Vimeo Tributes')
79         self.assertTrue(len(result['entries']) > 24)
80
81     def test_vimeo_user(self):
82         dl = FakeYDL()
83         ie = VimeoUserIE(dl)
84         result = ie.extract('http://vimeo.com/nkistudio/videos')
85         self.assertIsPlaylist(result)
86         self.assertEqual(result['title'], 'Nki')
87         self.assertTrue(len(result['entries']) > 65)
88
89     def test_vimeo_album(self):
90         dl = FakeYDL()
91         ie = VimeoAlbumIE(dl)
92         result = ie.extract('http://vimeo.com/album/2632481')
93         self.assertIsPlaylist(result)
94         self.assertEqual(result['title'], 'Staff Favorites: November 2013')
95         self.assertTrue(len(result['entries']) > 12)
96
97     def test_vimeo_groups(self):
98         dl = FakeYDL()
99         ie = VimeoGroupsIE(dl)
100         result = ie.extract('http://vimeo.com/groups/rolexawards')
101         self.assertIsPlaylist(result)
102         self.assertEqual(result['title'], 'Rolex Awards for Enterprise')
103         self.assertTrue(len(result['entries']) > 72)
104
105     def test_ustream_channel(self):
106         dl = FakeYDL()
107         ie = UstreamChannelIE(dl)
108         result = ie.extract('http://www.ustream.tv/channel/young-americans-for-liberty')
109         self.assertIsPlaylist(result)
110         self.assertEqual(result['id'], '5124905')
111         self.assertTrue(len(result['entries']) >= 6)
112
113     def test_soundcloud_set(self):
114         dl = FakeYDL()
115         ie = SoundcloudSetIE(dl)
116         result = ie.extract('https://soundcloud.com/the-concept-band/sets/the-royal-concept-ep')
117         self.assertIsPlaylist(result)
118         self.assertEqual(result['title'], 'The Royal Concept EP')
119         self.assertTrue(len(result['entries']) >= 6)
120
121     def test_soundcloud_user(self):
122         dl = FakeYDL()
123         ie = SoundcloudUserIE(dl)
124         result = ie.extract('https://soundcloud.com/the-concept-band')
125         self.assertIsPlaylist(result)
126         self.assertEqual(result['id'], '9615865')
127         self.assertTrue(len(result['entries']) >= 12)
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         self.assertTrue(len(result['entries']) >= 4)
147
148     def test_nhl_videocenter(self):
149         dl = FakeYDL()
150         ie = NHLVideocenterIE(dl)
151         result = ie.extract('http://video.canucks.nhl.com/videocenter/console?catid=999')
152         self.assertIsPlaylist(result)
153         self.assertEqual(result['id'], '999')
154         self.assertEqual(result['title'], 'Highlights')
155         self.assertEqual(len(result['entries']), 12)
156
157     def test_bambuser_channel(self):
158         dl = FakeYDL()
159         ie = BambuserChannelIE(dl)
160         result = ie.extract('http://bambuser.com/channel/pixelversity')
161         self.assertIsPlaylist(result)
162         self.assertEqual(result['title'], 'pixelversity')
163         self.assertTrue(len(result['entries']) >= 60)
164
165     def test_bandcamp_album(self):
166         dl = FakeYDL()
167         ie = BandcampAlbumIE(dl)
168         result = ie.extract('http://mpallante.bandcamp.com/album/nightmare-night-ep')
169         self.assertIsPlaylist(result)
170         self.assertEqual(result['title'], 'Nightmare Night EP')
171         self.assertTrue(len(result['entries']) >= 4)
172         
173     def test_smotri_community(self):
174         dl = FakeYDL()
175         ie = SmotriCommunityIE(dl)
176         result = ie.extract('http://smotri.com/community/video/kommuna')
177         self.assertIsPlaylist(result)
178         self.assertEqual(result['id'], 'kommuna')
179         self.assertEqual(result['title'], 'КПРФ')
180         self.assertTrue(len(result['entries']) >= 4)
181         
182     def test_smotri_user(self):
183         dl = FakeYDL()
184         ie = SmotriUserIE(dl)
185         result = ie.extract('http://smotri.com/user/inspector')
186         self.assertIsPlaylist(result)
187         self.assertEqual(result['id'], 'inspector')
188         self.assertEqual(result['title'], 'Inspector')
189         self.assertTrue(len(result['entries']) >= 9)
190
191     def test_AcademicEarthCourse(self):
192         dl = FakeYDL()
193         ie = AcademicEarthCourseIE(dl)
194         result = ie.extract('http://academicearth.org/playlists/laws-of-nature/')
195         self.assertIsPlaylist(result)
196         self.assertEqual(result['id'], 'laws-of-nature')
197         self.assertEqual(result['title'], 'Laws of Nature')
198         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.")
199         self.assertEqual(len(result['entries']), 4)
200         
201     def test_ivi_compilation(self):
202         dl = FakeYDL()
203         ie = IviCompilationIE(dl)
204         result = ie.extract('http://www.ivi.ru/watch/dezhurnyi_angel')
205         self.assertIsPlaylist(result)
206         self.assertEqual(result['id'], 'dezhurnyi_angel')
207         self.assertEqual(result['title'], 'Дежурный ангел (2010 - 2012)')
208         self.assertTrue(len(result['entries']) >= 23)
209
210     def test_ivi_compilation_season(self):
211         dl = FakeYDL()
212         ie = IviCompilationIE(dl)
213         result = ie.extract('http://www.ivi.ru/watch/dezhurnyi_angel/season2')
214         self.assertIsPlaylist(result)
215         self.assertEqual(result['id'], 'dezhurnyi_angel/season2')
216         self.assertEqual(result['title'], 'Дежурный ангел (2010 - 2012) 2 сезон')
217         self.assertTrue(len(result['entries']) >= 7)
218         
219     def test_imdb_list(self):
220         dl = FakeYDL()
221         ie = ImdbListIE(dl)
222         result = ie.extract('http://www.imdb.com/list/JFs9NWw6XI0')
223         self.assertIsPlaylist(result)
224         self.assertEqual(result['id'], 'JFs9NWw6XI0')
225         self.assertEqual(result['title'], 'March 23, 2012 Releases')
226         self.assertEqual(len(result['entries']), 7)
227
228     def test_khanacademy_topic(self):
229         dl = FakeYDL()
230         ie = KhanAcademyIE(dl)
231         result = ie.extract('https://www.khanacademy.org/math/applied-math/cryptography')
232         self.assertIsPlaylist(result)
233         self.assertEqual(result['id'], 'cryptography')
234         self.assertEqual(result['title'], 'Journey into cryptography')
235         self.assertEqual(result['description'], 'How have humans protected their secret messages through history? What has changed today?')
236         self.assertTrue(len(result['entries']) >= 3)
237
238     def test_EveryonesMixtape(self):
239         dl = FakeYDL()
240         ie = EveryonesMixtapeIE(dl)
241         result = ie.extract('http://everyonesmixtape.com/#/mix/m7m0jJAbMQi')
242         self.assertIsPlaylist(result)
243         self.assertEqual(result['id'], 'm7m0jJAbMQi')
244         self.assertEqual(result['title'], 'Driving')
245         self.assertEqual(len(result['entries']), 24)
246         
247     def test_rutube_channel(self):
248         dl = FakeYDL()
249         ie = RutubeChannelIE(dl)
250         result = ie.extract('http://rutube.ru/tags/video/1409')
251         self.assertIsPlaylist(result)
252         self.assertEqual(result['id'], '1409')
253         self.assertTrue(len(result['entries']) >= 34)
254
255     def test_multiple_brightcove_videos(self):
256         # https://github.com/rg3/youtube-dl/issues/2283
257         dl = FakeYDL()
258         ie = GenericIE(dl)
259         result = ie.extract('http://www.newyorker.com/online/blogs/newsdesk/2014/01/always-never-nuclear-command-and-control.html')
260         self.assertIsPlaylist(result)
261         self.assertEqual(result['id'], 'always-never-nuclear-command-and-control')
262         self.assertEqual(result['title'], 'Always/Never: A Little-Seen Movie About Nuclear Command and Control : The New Yorker')
263         self.assertEqual(len(result['entries']), 3)
264
265     def test_GoogleSearch(self):
266         dl = FakeYDL()
267         ie = GoogleSearchIE(dl)
268         result = ie.extract('gvsearch15:python language')
269         self.assertIsPlaylist(result)
270         self.assertEqual(result['id'], 'python language')
271         self.assertEqual(result['title'], 'python language')
272         self.assertEqual(len(result['entries']), 15)
273
274     def test_generic_rss_feed(self):
275         dl = FakeYDL()
276         ie = GenericIE(dl)
277         result = ie.extract('http://phihag.de/2014/youtube-dl/rss.xml')
278         self.assertIsPlaylist(result)
279         self.assertEqual(result['id'], 'http://phihag.de/2014/youtube-dl/rss.xml')
280         self.assertEqual(result['title'], 'Zero Punctuation')
281         self.assertTrue(len(result['entries']) > 10)
282
283     def test_ted_playlist(self):
284         dl = FakeYDL()
285         ie = TEDIE(dl)
286         result = ie.extract('http://www.ted.com/playlists/who_are_the_hackers')
287         self.assertIsPlaylist(result)
288         self.assertEqual(result['id'], '10')
289         self.assertEqual(result['title'], 'Who are the hackers?')
290         self.assertTrue(len(result['entries']) >= 6)
291
292     def test_toypics_user(self):
293         dl = FakeYDL()
294         ie = ToypicsUserIE(dl)
295         result = ie.extract('http://videos.toypics.net/Mikey')
296         self.assertIsPlaylist(result)
297         self.assertEqual(result['id'], 'Mikey')
298         self.assertTrue(len(result['entries']) >= 17)
299
300     def test_xtube_user(self):
301         dl = FakeYDL()
302         ie = XTubeUserIE(dl)
303         result = ie.extract('http://www.xtube.com/community/profile.php?user=greenshowers')
304         self.assertIsPlaylist(result)
305         self.assertEqual(result['id'], 'greenshowers')
306         self.assertTrue(len(result['entries']) >= 155)
307
308     def test_InstagramUser(self):
309         dl = FakeYDL()
310         ie = InstagramUserIE(dl)
311         result = ie.extract('http://instagram.com/porsche')
312         self.assertIsPlaylist(result)
313         self.assertEqual(result['id'], 'porsche')
314         self.assertTrue(len(result['entries']) >= 2)
315         test_video = next(
316             e for e in result['entries']
317             if e['id'] == '614605558512799803_462752227')
318         dl.add_default_extra_info(test_video, ie, '(irrelevant URL)')
319         dl.process_video_result(test_video, download=False)
320         EXPECTED = {
321             'id': '614605558512799803_462752227',
322             'ext': 'mp4',
323             'title': '#Porsche Intelligent Performance.',
324             'thumbnail': 're:^https?://.*\.jpg',
325             'uploader': 'Porsche',
326             'uploader_id': 'porsche',
327             'timestamp': 1387486713,
328             'upload_date': '20131219',
329         }
330         expect_info_dict(self, EXPECTED, test_video)
331
332     def test_CSpan_playlist(self):
333         dl = FakeYDL()
334         ie = CSpanIE(dl)
335         result = ie.extract(
336             'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall')
337         self.assertIsPlaylist(result)
338         self.assertEqual(result['id'], '342759')
339         self.assertEqual(
340             result['title'], 'General Motors Ignition Switch Recall')
341         whole_duration = sum(e['duration'] for e in result['entries'])
342         self.assertEqual(whole_duration, 14855)
343
344     def test_aol_playlist(self):
345         dl = FakeYDL()
346         ie = AolIE(dl)
347         result = ie.extract(
348             'http://on.aol.com/playlist/brace-yourself---todays-weirdest-news-152147?icid=OnHomepageC4_Omg_Img#_videoid=518184316')
349         self.assertIsPlaylist(result)
350         self.assertEqual(result['id'], '152147')
351         self.assertEqual(
352             result['title'], 'Brace Yourself - Today\'s Weirdest News')
353         self.assertTrue(len(result['entries']) >= 10)
354
355 if __name__ == '__main__':
356     unittest.main()