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