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