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