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