]> jfr.im git - yt-dlp.git/blame - test/test_playlists.py
[teachertube] Add support for new URL formats
[yt-dlp.git] / test / test_playlists.py
CommitLineData
a3c736de 1#!/usr/bin/env python
39baacc4 2# encoding: utf-8
a3c736de 3
ecfef3e5
PH
4from __future__ import unicode_literals
5
a3c736de
JMF
6# Allow direct execution
7import os
44a5f171
PH
8import sys
9import unittest
10sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
11
ea38e55f 12from test.helper import (
20991253 13 assertRegexpMatches,
ea38e55f
PH
14 expect_info_dict,
15 FakeYDL,
16)
a3c736de 17
39baacc4 18from youtube_dl.extractor import (
d90df974 19 AcademicEarthCourseIE,
39baacc4
JMF
20 DailymotionPlaylistIE,
21 DailymotionUserIE,
22 VimeoChannelIE,
55a10eab 23 VimeoUserIE,
5cc14c2f 24 VimeoAlbumIE,
fb30ec22 25 VimeoGroupsIE,
ea783d01 26 VineUserIE,
39baacc4 27 UstreamChannelIE,
12c167c8 28 SoundcloudSetIE,
39baacc4 29 SoundcloudUserIE,
20991253 30 SoundcloudPlaylistIE,
b4e74474 31 TeacherTubeClassroomIE,
b00ca882 32 LivestreamIE,
91dbaef4 33 NHLVideocenterIE,
165e3bb6 34 BambuserChannelIE,
5270d8cb 35 BandcampAlbumIE,
36 SmotriCommunityIE,
5ce54a82 37 SmotriUserIE,
41cc67c5 38 IviCompilationIE,
4fb757d1 39 ImdbListIE,
3d3538e4 40 KhanAcademyIE,
484aaeb2 41 EveryonesMixtapeIE,
87fac323 42 RutubeChannelIE,
fd69098a 43 RutubePersonIE,
ccf9114e 44 GoogleSearchIE,
99877772 45 GenericIE,
ca1fee34 46 TEDIE,
231f76b5 47 ToypicsUserIE,
9f5809b3 48 XTubeUserIE,
ea38e55f 49 InstagramUserIE,
aea6e7fc 50 CSpanIE,
de906ef5 51 AolIE,
39baacc4 52)
a3c736de 53
a3c736de
JMF
54
55class TestPlaylists(unittest.TestCase):
56 def assertIsPlaylist(self, info):
57 """Make sure the info has '_type' set to 'playlist'"""
58 self.assertEqual(info['_type'], 'playlist')
59
60 def test_dailymotion_playlist(self):
61 dl = FakeYDL()
62 ie = DailymotionPlaylistIE(dl)
63 result = ie.extract('http://www.dailymotion.com/playlist/xv4bw_nqtv_sport/1#video=xl8v3q')
64 self.assertIsPlaylist(result)
ecfef3e5 65 self.assertEqual(result['title'], 'SPORT')
a3c736de 66 self.assertTrue(len(result['entries']) > 20)
b00ca882 67
39baacc4
JMF
68 def test_dailymotion_user(self):
69 dl = FakeYDL()
70 ie = DailymotionUserIE(dl)
99043c2e 71 result = ie.extract('https://www.dailymotion.com/user/nqtv')
39baacc4 72 self.assertIsPlaylist(result)
99043c2e
JMF
73 self.assertEqual(result['title'], 'Rémi Gaillard')
74 self.assertTrue(len(result['entries']) >= 100)
a3c736de 75
caeefc29
JMF
76 def test_vimeo_channel(self):
77 dl = FakeYDL()
78 ie = VimeoChannelIE(dl)
79 result = ie.extract('http://vimeo.com/channels/tributes')
80 self.assertIsPlaylist(result)
ecfef3e5 81 self.assertEqual(result['title'], 'Vimeo Tributes')
caeefc29
JMF
82 self.assertTrue(len(result['entries']) > 24)
83
55a10eab
JMF
84 def test_vimeo_user(self):
85 dl = FakeYDL()
86 ie = VimeoUserIE(dl)
87 result = ie.extract('http://vimeo.com/nkistudio/videos')
88 self.assertIsPlaylist(result)
ecfef3e5 89 self.assertEqual(result['title'], 'Nki')
55a10eab
JMF
90 self.assertTrue(len(result['entries']) > 65)
91
5cc14c2f
JMF
92 def test_vimeo_album(self):
93 dl = FakeYDL()
94 ie = VimeoAlbumIE(dl)
95 result = ie.extract('http://vimeo.com/album/2632481')
96 self.assertIsPlaylist(result)
ecfef3e5 97 self.assertEqual(result['title'], 'Staff Favorites: November 2013')
5cc14c2f
JMF
98 self.assertTrue(len(result['entries']) > 12)
99
fb30ec22
JMF
100 def test_vimeo_groups(self):
101 dl = FakeYDL()
102 ie = VimeoGroupsIE(dl)
103 result = ie.extract('http://vimeo.com/groups/rolexawards')
104 self.assertIsPlaylist(result)
ecfef3e5 105 self.assertEqual(result['title'], 'Rolex Awards for Enterprise')
fb30ec22
JMF
106 self.assertTrue(len(result['entries']) > 72)
107
ea783d01
JN
108 def test_vine_user(self):
109 dl = FakeYDL()
110 ie = VineUserIE(dl)
111 result = ie.extract('https://vine.co/Visa')
112 self.assertIsPlaylist(result)
113 self.assertTrue(len(result['entries']) >= 50)
114
74ac9bdd
JMF
115 def test_ustream_channel(self):
116 dl = FakeYDL()
117 ie = UstreamChannelIE(dl)
a14e1538 118 result = ie.extract('http://www.ustream.tv/channel/channeljapan')
74ac9bdd 119 self.assertIsPlaylist(result)
a14e1538
PP
120 self.assertEqual(result['id'], '10874166')
121 self.assertTrue(len(result['entries']) >= 54)
74ac9bdd 122
12c167c8
JMF
123 def test_soundcloud_set(self):
124 dl = FakeYDL()
125 ie = SoundcloudSetIE(dl)
126 result = ie.extract('https://soundcloud.com/the-concept-band/sets/the-royal-concept-ep')
127 self.assertIsPlaylist(result)
ecfef3e5 128 self.assertEqual(result['title'], 'The Royal Concept EP')
12c167c8
JMF
129 self.assertTrue(len(result['entries']) >= 6)
130
92790f4e
JMF
131 def test_soundcloud_user(self):
132 dl = FakeYDL()
133 ie = SoundcloudUserIE(dl)
134 result = ie.extract('https://soundcloud.com/the-concept-band')
135 self.assertIsPlaylist(result)
ecfef3e5 136 self.assertEqual(result['id'], '9615865')
92790f4e
JMF
137 self.assertTrue(len(result['entries']) >= 12)
138
20991253
PH
139 def test_soundcloud_playlist(self):
140 dl = FakeYDL()
141 ie = SoundcloudPlaylistIE(dl)
142 result = ie.extract('http://api.soundcloud.com/playlists/4110309')
143 self.assertIsPlaylist(result)
144 self.assertEqual(result['id'], '4110309')
145 self.assertEqual(result['title'], 'TILT Brass - Bowery Poetry Club, August \'03 [Non-Site SCR 02]')
146 assertRegexpMatches(
147 self, result['description'], r'TILT Brass - Bowery Poetry Club')
148 self.assertEqual(len(result['entries']), 6)
149
b00ca882
JMF
150 def test_livestream_event(self):
151 dl = FakeYDL()
152 ie = LivestreamIE(dl)
153 result = ie.extract('http://new.livestream.com/tedx/cityenglish')
154 self.assertIsPlaylist(result)
ecfef3e5 155 self.assertEqual(result['title'], 'TEDCity2.0 (English)')
b00ca882
JMF
156 self.assertTrue(len(result['entries']) >= 4)
157
91dbaef4
JMF
158 def test_nhl_videocenter(self):
159 dl = FakeYDL()
160 ie = NHLVideocenterIE(dl)
161 result = ie.extract('http://video.canucks.nhl.com/videocenter/console?catid=999')
162 self.assertIsPlaylist(result)
ecfef3e5
PH
163 self.assertEqual(result['id'], '999')
164 self.assertEqual(result['title'], 'Highlights')
91dbaef4
JMF
165 self.assertEqual(len(result['entries']), 12)
166
165e3bb6
JMF
167 def test_bambuser_channel(self):
168 dl = FakeYDL()
169 ie = BambuserChannelIE(dl)
170 result = ie.extract('http://bambuser.com/channel/pixelversity')
171 self.assertIsPlaylist(result)
ecfef3e5 172 self.assertEqual(result['title'], 'pixelversity')
d3b30148 173 self.assertTrue(len(result['entries']) >= 60)
165e3bb6 174
09804265
JMF
175 def test_bandcamp_album(self):
176 dl = FakeYDL()
177 ie = BandcampAlbumIE(dl)
178 result = ie.extract('http://mpallante.bandcamp.com/album/nightmare-night-ep')
179 self.assertIsPlaylist(result)
ecfef3e5 180 self.assertEqual(result['title'], 'Nightmare Night EP')
09804265 181 self.assertTrue(len(result['entries']) >= 4)
5270d8cb 182
183 def test_smotri_community(self):
184 dl = FakeYDL()
185 ie = SmotriCommunityIE(dl)
186 result = ie.extract('http://smotri.com/community/video/kommuna')
187 self.assertIsPlaylist(result)
ecfef3e5
PH
188 self.assertEqual(result['id'], 'kommuna')
189 self.assertEqual(result['title'], 'КПРФ')
5270d8cb 190 self.assertTrue(len(result['entries']) >= 4)
191
192 def test_smotri_user(self):
193 dl = FakeYDL()
194 ie = SmotriUserIE(dl)
195 result = ie.extract('http://smotri.com/user/inspector')
196 self.assertIsPlaylist(result)
ecfef3e5
PH
197 self.assertEqual(result['id'], 'inspector')
198 self.assertEqual(result['title'], 'Inspector')
5270d8cb 199 self.assertTrue(len(result['entries']) >= 9)
09804265 200
d90df974
PH
201 def test_AcademicEarthCourse(self):
202 dl = FakeYDL()
203 ie = AcademicEarthCourseIE(dl)
9e57ce71 204 result = ie.extract('http://academicearth.org/playlists/laws-of-nature/')
d90df974 205 self.assertIsPlaylist(result)
9e57ce71
JMF
206 self.assertEqual(result['id'], 'laws-of-nature')
207 self.assertEqual(result['title'], 'Laws of Nature')
208 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.")
209 self.assertEqual(len(result['entries']), 4)
8c21b7c6 210
211 def test_ivi_compilation(self):
212 dl = FakeYDL()
213 ie = IviCompilationIE(dl)
6ebb46c1 214 result = ie.extract('http://www.ivi.ru/watch/dvoe_iz_lartsa')
8c21b7c6 215 self.assertIsPlaylist(result)
6ebb46c1
S
216 self.assertEqual(result['id'], 'dvoe_iz_lartsa')
217 self.assertEqual(result['title'], 'Двое из ларца (2006 - 2008)')
218 self.assertTrue(len(result['entries']) >= 24)
3a9d6790 219
8c21b7c6 220 def test_ivi_compilation_season(self):
221 dl = FakeYDL()
222 ie = IviCompilationIE(dl)
6ebb46c1 223 result = ie.extract('http://www.ivi.ru/watch/dvoe_iz_lartsa/season1')
8c21b7c6 224 self.assertIsPlaylist(result)
6ebb46c1
S
225 self.assertEqual(result['id'], 'dvoe_iz_lartsa/season1')
226 self.assertEqual(result['title'], 'Двое из ларца (2006 - 2008) 1 сезон')
227 self.assertTrue(len(result['entries']) >= 12)
41cc67c5 228
229 def test_imdb_list(self):
230 dl = FakeYDL()
231 ie = ImdbListIE(dl)
98669ed7 232 result = ie.extract('http://www.imdb.com/list/JFs9NWw6XI0')
41cc67c5 233 self.assertIsPlaylist(result)
98669ed7 234 self.assertEqual(result['id'], 'JFs9NWw6XI0')
235 self.assertEqual(result['title'], 'March 23, 2012 Releases')
236 self.assertEqual(len(result['entries']), 7)
d90df974 237
3d3538e4
PH
238 def test_khanacademy_topic(self):
239 dl = FakeYDL()
240 ie = KhanAcademyIE(dl)
241 result = ie.extract('https://www.khanacademy.org/math/applied-math/cryptography')
242 self.assertIsPlaylist(result)
ecfef3e5
PH
243 self.assertEqual(result['id'], 'cryptography')
244 self.assertEqual(result['title'], 'Journey into cryptography')
245 self.assertEqual(result['description'], 'How have humans protected their secret messages through history? What has changed today?')
3d3538e4
PH
246 self.assertTrue(len(result['entries']) >= 3)
247
484aaeb2
PH
248 def test_EveryonesMixtape(self):
249 dl = FakeYDL()
250 ie = EveryonesMixtapeIE(dl)
251 result = ie.extract('http://everyonesmixtape.com/#/mix/m7m0jJAbMQi')
252 self.assertIsPlaylist(result)
253 self.assertEqual(result['id'], 'm7m0jJAbMQi')
254 self.assertEqual(result['title'], 'Driving')
255 self.assertEqual(len(result['entries']), 24)
87fac323 256
257 def test_rutube_channel(self):
258 dl = FakeYDL()
259 ie = RutubeChannelIE(dl)
fd69098a 260 result = ie.extract('http://rutube.ru/tags/video/1800/')
87fac323 261 self.assertIsPlaylist(result)
fd69098a
S
262 self.assertEqual(result['id'], '1800')
263 self.assertTrue(len(result['entries']) >= 68)
264
265 def test_rutube_person(self):
266 dl = FakeYDL()
267 ie = RutubePersonIE(dl)
268 result = ie.extract('http://rutube.ru/video/person/313878/')
269 self.assertIsPlaylist(result)
270 self.assertEqual(result['id'], '313878')
271 self.assertTrue(len(result['entries']) >= 37)
484aaeb2 272
99877772
PH
273 def test_multiple_brightcove_videos(self):
274 # https://github.com/rg3/youtube-dl/issues/2283
275 dl = FakeYDL()
276 ie = GenericIE(dl)
277 result = ie.extract('http://www.newyorker.com/online/blogs/newsdesk/2014/01/always-never-nuclear-command-and-control.html')
278 self.assertIsPlaylist(result)
279 self.assertEqual(result['id'], 'always-never-nuclear-command-and-control')
280 self.assertEqual(result['title'], 'Always/Never: A Little-Seen Movie About Nuclear Command and Control : The New Yorker')
281 self.assertEqual(len(result['entries']), 3)
282
ccf9114e
PH
283 def test_GoogleSearch(self):
284 dl = FakeYDL()
285 ie = GoogleSearchIE(dl)
286 result = ie.extract('gvsearch15:python language')
287 self.assertIsPlaylist(result)
288 self.assertEqual(result['id'], 'python language')
289 self.assertEqual(result['title'], 'python language')
c3d36f13 290 self.assertEqual(len(result['entries']), 15)
d90df974 291
4fc946b5
PH
292 def test_generic_rss_feed(self):
293 dl = FakeYDL()
294 ie = GenericIE(dl)
6a724239 295 result = ie.extract('http://phihag.de/2014/youtube-dl/rss.xml')
4fc946b5 296 self.assertIsPlaylist(result)
6a724239 297 self.assertEqual(result['id'], 'http://phihag.de/2014/youtube-dl/rss.xml')
4fc946b5
PH
298 self.assertEqual(result['title'], 'Zero Punctuation')
299 self.assertTrue(len(result['entries']) > 10)
300
ca1fee34
JMF
301 def test_ted_playlist(self):
302 dl = FakeYDL()
303 ie = TEDIE(dl)
304 result = ie.extract('http://www.ted.com/playlists/who_are_the_hackers')
305 self.assertIsPlaylist(result)
306 self.assertEqual(result['id'], '10')
307 self.assertEqual(result['title'], 'Who are the hackers?')
308 self.assertTrue(len(result['entries']) >= 6)
309
231f76b5
PH
310 def test_toypics_user(self):
311 dl = FakeYDL()
312 ie = ToypicsUserIE(dl)
313 result = ie.extract('http://videos.toypics.net/Mikey')
314 self.assertIsPlaylist(result)
315 self.assertEqual(result['id'], 'Mikey')
316 self.assertTrue(len(result['entries']) >= 17)
317
9f5809b3 318 def test_xtube_user(self):
319 dl = FakeYDL()
320 ie = XTubeUserIE(dl)
321 result = ie.extract('http://www.xtube.com/community/profile.php?user=greenshowers')
322 self.assertIsPlaylist(result)
323 self.assertEqual(result['id'], 'greenshowers')
324 self.assertTrue(len(result['entries']) >= 155)
325
ea38e55f
PH
326 def test_InstagramUser(self):
327 dl = FakeYDL()
328 ie = InstagramUserIE(dl)
329 result = ie.extract('http://instagram.com/porsche')
330 self.assertIsPlaylist(result)
331 self.assertEqual(result['id'], 'porsche')
332 self.assertTrue(len(result['entries']) >= 2)
333 test_video = next(
334 e for e in result['entries']
335 if e['id'] == '614605558512799803_462752227')
336 dl.add_default_extra_info(test_video, ie, '(irrelevant URL)')
337 dl.process_video_result(test_video, download=False)
338 EXPECTED = {
339 'id': '614605558512799803_462752227',
340 'ext': 'mp4',
341 'title': '#Porsche Intelligent Performance.',
342 'thumbnail': 're:^https?://.*\.jpg',
343 'uploader': 'Porsche',
344 'uploader_id': 'porsche',
912b38b4
PH
345 'timestamp': 1387486713,
346 'upload_date': '20131219',
ea38e55f
PH
347 }
348 expect_info_dict(self, EXPECTED, test_video)
349
aea6e7fc
PH
350 def test_CSpan_playlist(self):
351 dl = FakeYDL()
352 ie = CSpanIE(dl)
353 result = ie.extract(
354 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall')
355 self.assertIsPlaylist(result)
356 self.assertEqual(result['id'], '342759')
357 self.assertEqual(
358 result['title'], 'General Motors Ignition Switch Recall')
aea6e7fc
PH
359 whole_duration = sum(e['duration'] for e in result['entries'])
360 self.assertEqual(whole_duration, 14855)
361
de906ef5
PH
362 def test_aol_playlist(self):
363 dl = FakeYDL()
364 ie = AolIE(dl)
365 result = ie.extract(
366 'http://on.aol.com/playlist/brace-yourself---todays-weirdest-news-152147?icid=OnHomepageC4_Omg_Img#_videoid=518184316')
367 self.assertIsPlaylist(result)
368 self.assertEqual(result['id'], '152147')
369 self.assertEqual(
370 result['title'], 'Brace Yourself - Today\'s Weirdest News')
371 self.assertTrue(len(result['entries']) >= 10)
ea38e55f 372
b4e74474 373 def test_TeacherTubeClassroom(self):
374 dl = FakeYDL()
375 ie = TeacherTubeClassroomIE(dl)
376 result = ie.extract('http://www.teachertube.com/view_classroom.php?user=rbhagwati2')
377 self.assertIsPlaylist(result)
378 self.assertEqual(result['id'], 'rbhagwati2')
379 self.assertTrue(len(result['entries']) >= 20)
380
a3c736de
JMF
381if __name__ == '__main__':
382 unittest.main()