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