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