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