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