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