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