]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_youtube_lists.py
410f9edc297036d7aeb59250c3241dc10bb7cf2d
[youtubedl] / test / test_youtube_lists.py
1 #!/usr/bin/env python
2
3 # Allow direct execution
4 import os
5 import sys
6 import unittest
7 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
8
9 from test.helper import FakeYDL
10
11
12 from youtube_dl.extractor import (
13 YoutubePlaylistIE,
14 YoutubeIE,
15 YoutubeChannelIE,
16 YoutubeShowIE,
17 YoutubeTopListIE,
18 YoutubeSearchURLIE,
19 )
20
21
22 class TestYoutubeLists(unittest.TestCase):
23 def assertIsPlaylist(self, info):
24 """Make sure the info has '_type' set to 'playlist'"""
25 self.assertEqual(info['_type'], 'playlist')
26
27 def test_youtube_playlist_noplaylist(self):
28 dl = FakeYDL()
29 dl.params['noplaylist'] = True
30 ie = YoutubePlaylistIE(dl)
31 result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
32 self.assertEqual(result['_type'], 'url')
33 self.assertEqual(YoutubeIE().extract_id(result['url']), 'FXxLjLQi3Fg')
34
35 def test_youtube_course(self):
36 dl = FakeYDL()
37 ie = YoutubePlaylistIE(dl)
38 # TODO find a > 100 (paginating?) videos course
39 result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
40 entries = result['entries']
41 self.assertEqual(YoutubeIE().extract_id(entries[0]['url']), 'j9WZyLZCBzs')
42 self.assertEqual(len(entries), 25)
43 self.assertEqual(YoutubeIE().extract_id(entries[-1]['url']), 'rYefUsYuEp0')
44
45 def test_youtube_mix(self):
46 dl = FakeYDL()
47 ie = YoutubePlaylistIE(dl)
48 result = ie.extract('https://www.youtube.com/watch?v=W01L70IGBgE&index=2&list=RDOQpdSVF_k_w')
49 entries = result['entries']
50 self.assertTrue(len(entries) >= 20)
51 original_video = entries[0]
52 self.assertEqual(original_video['id'], 'OQpdSVF_k_w')
53
54 def test_youtube_toptracks(self):
55 print('Skipping: The playlist page gives error 500')
56 return
57 dl = FakeYDL()
58 ie = YoutubePlaylistIE(dl)
59 result = ie.extract('https://www.youtube.com/playlist?list=MCUS')
60 entries = result['entries']
61 self.assertEqual(len(entries), 100)
62
63 if __name__ == '__main__':
64 unittest.main()