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