]>
Commit | Line | Data |
---|---|---|
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 yt_dlp.extractor import ( | |
14 | YoutubePlaylistIE, | |
15 | YoutubeTabIE, | |
16 | YoutubeIE, | |
17 | ) | |
18 | ||
19 | ||
20 | class TestYoutubeLists(unittest.TestCase): | |
21 | def assertIsPlaylist(self, info): | |
22 | """Make sure the info has '_type' set to 'playlist'""" | |
23 | self.assertEqual(info['_type'], 'playlist') | |
24 | ||
25 | def test_youtube_playlist_noplaylist(self): | |
26 | dl = FakeYDL() | |
27 | dl.params['noplaylist'] = True | |
28 | ie = YoutubePlaylistIE(dl) | |
29 | result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re') | |
30 | self.assertEqual(result['_type'], 'url') | |
31 | self.assertEqual(YoutubeIE().extract_id(result['url']), 'FXxLjLQi3Fg') | |
32 | ||
33 | def test_youtube_course(self): | |
34 | dl = FakeYDL() | |
35 | ie = YoutubePlaylistIE(dl) | |
36 | # TODO find a > 100 (paginating?) videos course | |
37 | result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8') | |
38 | entries = list(result['entries']) | |
39 | self.assertEqual(YoutubeIE().extract_id(entries[0]['url']), 'j9WZyLZCBzs') | |
40 | self.assertEqual(len(entries), 25) | |
41 | self.assertEqual(YoutubeIE().extract_id(entries[-1]['url']), 'rYefUsYuEp0') | |
42 | ||
43 | def test_youtube_mix(self): | |
44 | dl = FakeYDL() | |
45 | ie = YoutubePlaylistIE(dl) | |
46 | result = ie.extract('https://www.youtube.com/watch?v=W01L70IGBgE&index=2&list=RDOQpdSVF_k_w') | |
47 | entries = result['entries'] | |
48 | self.assertTrue(len(entries) >= 50) | |
49 | original_video = entries[0] | |
50 | self.assertEqual(original_video['id'], 'OQpdSVF_k_w') | |
51 | ||
52 | def test_youtube_toptracks(self): | |
53 | print('Skipping: The playlist page gives error 500') | |
54 | return | |
55 | dl = FakeYDL() | |
56 | ie = YoutubePlaylistIE(dl) | |
57 | result = ie.extract('https://www.youtube.com/playlist?list=MCUS') | |
58 | entries = result['entries'] | |
59 | self.assertEqual(len(entries), 100) | |
60 | ||
61 | def test_youtube_flat_playlist_extraction(self): | |
62 | dl = FakeYDL() | |
63 | dl.params['extract_flat'] = True | |
64 | ie = YoutubeTabIE(dl) | |
65 | result = ie.extract('https://www.youtube.com/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc') | |
66 | self.assertIsPlaylist(result) | |
67 | entries = list(result['entries']) | |
68 | self.assertTrue(len(entries) == 1) | |
69 | video = entries[0] | |
70 | self.assertEqual(video['_type'], 'url_transparent') | |
71 | self.assertEqual(video['ie_key'], 'Youtube') | |
72 | self.assertEqual(video['id'], 'BaW_jenozKc') | |
73 | self.assertEqual(video['url'], 'BaW_jenozKc') | |
74 | self.assertEqual(video['title'], 'youtube-dl test video "\'/\\ä↭𝕐') | |
75 | self.assertEqual(video['duration'], 10) | |
76 | self.assertEqual(video['uploader'], 'Philipp Hagemeister') | |
77 | ||
78 | ||
79 | if __name__ == '__main__': | |
80 | unittest.main() |