]>
Commit | Line | Data |
---|---|---|
9789a05c FV |
1 | #!/usr/bin/env python |
2 | ||
44a5f171 PH |
3 | # Allow direct execution |
4 | import os | |
9789a05c FV |
5 | import sys |
6 | import unittest | |
44a5f171 PH |
7 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
8 | ||
d0efb9ec | 9 | from test.helper import FakeYDL |
9789a05c | 10 | |
9789a05c | 11 | |
44a5f171 | 12 | from youtube_dl.extractor import ( |
44a5f171 PH |
13 | YoutubePlaylistIE, |
14 | YoutubeIE, | |
44a5f171 | 15 | ) |
9789a05c | 16 | |
9789a05c FV |
17 | |
18 | class TestYoutubeLists(unittest.TestCase): | |
44a5f171 | 19 | def assertIsPlaylist(self, info): |
8a38a194 JMF |
20 | """Make sure the info has '_type' set to 'playlist'""" |
21 | self.assertEqual(info['_type'], 'playlist') | |
22 | ||
d4d9920a FV |
23 | def test_youtube_playlist_noplaylist(self): |
24 | dl = FakeYDL() | |
25 | dl.params['noplaylist'] = True | |
26 | ie = YoutubePlaylistIE(dl) | |
27 | result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re') | |
28 | self.assertEqual(result['_type'], 'url') | |
97665381 | 29 | self.assertEqual(YoutubeIE().extract_id(result['url']), 'FXxLjLQi3Fg') |
5f6a1245 | 30 | |
9789a05c | 31 | def test_youtube_course(self): |
8bf8b5a5 | 32 | dl = FakeYDL() |
679790ee | 33 | ie = YoutubePlaylistIE(dl) |
9789a05c | 34 | # TODO find a > 100 (paginating?) videos course |
dcbb4580 | 35 | result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8') |
8a38a194 | 36 | entries = result['entries'] |
97665381 | 37 | self.assertEqual(YoutubeIE().extract_id(entries[0]['url']), 'j9WZyLZCBzs') |
8a38a194 | 38 | self.assertEqual(len(entries), 25) |
97665381 | 39 | self.assertEqual(YoutubeIE().extract_id(entries[-1]['url']), 'rYefUsYuEp0') |
9789a05c | 40 | |
652cdaa2 JMF |
41 | def test_youtube_mix(self): |
42 | dl = FakeYDL() | |
43 | ie = YoutubePlaylistIE(dl) | |
24577db2 | 44 | result = ie.extract('https://www.youtube.com/watch?v=W01L70IGBgE&index=2&list=RDOQpdSVF_k_w') |
652cdaa2 JMF |
45 | entries = result['entries'] |
46 | self.assertTrue(len(entries) >= 20) | |
47 | original_video = entries[0] | |
24577db2 | 48 | self.assertEqual(original_video['id'], 'OQpdSVF_k_w') |
652cdaa2 | 49 | |
d67cc9fa | 50 | def test_youtube_toptracks(self): |
ea5a0be8 JMF |
51 | print('Skipping: The playlist page gives error 500') |
52 | return | |
d67cc9fa JMF |
53 | dl = FakeYDL() |
54 | ie = YoutubePlaylistIE(dl) | |
55 | result = ie.extract('https://www.youtube.com/playlist?list=MCUS') | |
56 | entries = result['entries'] | |
57 | self.assertEqual(len(entries), 100) | |
58 | ||
9789a05c FV |
59 | if __name__ == '__main__': |
60 | unittest.main() |