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