]>
Commit | Line | Data |
---|---|---|
cc52de43 | 1 | #!/usr/bin/env python3 |
dcddc10a | 2 | from __future__ import unicode_literals |
9789a05c | 3 | |
44a5f171 PH |
4 | # Allow direct execution |
5 | import os | |
9789a05c FV |
6 | import sys |
7 | import unittest | |
44a5f171 PH |
8 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
9 | ||
060ac762 | 10 | from test.helper import FakeYDL, is_download_test |
9789a05c | 11 | |
9789a05c | 12 | |
7a5c1cfe | 13 | from yt_dlp.extractor import ( |
44a5f171 | 14 | YoutubePlaylistIE, |
bc2ca1bb | 15 | YoutubeTabIE, |
44a5f171 | 16 | YoutubeIE, |
44a5f171 | 17 | ) |
9789a05c | 18 | |
9789a05c | 19 | |
060ac762 | 20 | @is_download_test |
9789a05c | 21 | class TestYoutubeLists(unittest.TestCase): |
44a5f171 | 22 | def assertIsPlaylist(self, info): |
8a38a194 JMF |
23 | """Make sure the info has '_type' set to 'playlist'""" |
24 | self.assertEqual(info['_type'], 'playlist') | |
25 | ||
d4d9920a FV |
26 | def test_youtube_playlist_noplaylist(self): |
27 | dl = FakeYDL() | |
28 | dl.params['noplaylist'] = True | |
dd2a987d | 29 | ie = YoutubeTabIE(dl) |
d4d9920a FV |
30 | result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re') |
31 | self.assertEqual(result['_type'], 'url') | |
dd2a987d | 32 | self.assertEqual(YoutubeIE.extract_id(result['url']), 'FXxLjLQi3Fg') |
5f6a1245 | 33 | |
9789a05c | 34 | def test_youtube_course(self): |
dd2a987d | 35 | print('Skipping: Course URLs no longer exists') |
36 | return | |
8bf8b5a5 | 37 | dl = FakeYDL() |
679790ee | 38 | ie = YoutubePlaylistIE(dl) |
9789a05c | 39 | # TODO find a > 100 (paginating?) videos course |
dcbb4580 | 40 | result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8') |
a7aab0c2 | 41 | entries = list(result['entries']) |
dd2a987d | 42 | self.assertEqual(YoutubeIE.extract_id(entries[0]['url']), 'j9WZyLZCBzs') |
8a38a194 | 43 | self.assertEqual(len(entries), 25) |
dd2a987d | 44 | self.assertEqual(YoutubeIE.extract_id(entries[-1]['url']), 'rYefUsYuEp0') |
9789a05c | 45 | |
652cdaa2 JMF |
46 | def test_youtube_mix(self): |
47 | dl = FakeYDL() | |
dd2a987d | 48 | ie = YoutubeTabIE(dl) |
49 | result = ie.extract('https://www.youtube.com/watch?v=tyITL_exICo&list=RDCLAK5uy_kLWIr9gv1XLlPbaDS965-Db4TrBoUTxQ8') | |
50 | entries = list(result['entries']) | |
1b6182d8 | 51 | self.assertTrue(len(entries) >= 50) |
652cdaa2 | 52 | original_video = entries[0] |
dd2a987d | 53 | self.assertEqual(original_video['id'], 'tyITL_exICo') |
652cdaa2 | 54 | |
d67cc9fa | 55 | def test_youtube_toptracks(self): |
ea5a0be8 JMF |
56 | print('Skipping: The playlist page gives error 500') |
57 | return | |
d67cc9fa JMF |
58 | dl = FakeYDL() |
59 | ie = YoutubePlaylistIE(dl) | |
60 | result = ie.extract('https://www.youtube.com/playlist?list=MCUS') | |
61 | entries = result['entries'] | |
62 | self.assertEqual(len(entries), 100) | |
63 | ||
bc2ca1bb | 64 | def test_youtube_flat_playlist_extraction(self): |
8e5b1219 S |
65 | dl = FakeYDL() |
66 | dl.params['extract_flat'] = True | |
bc2ca1bb | 67 | ie = YoutubeTabIE(dl) |
68 | result = ie.extract('https://www.youtube.com/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc') | |
8e5b1219 | 69 | self.assertIsPlaylist(result) |
bc2ca1bb | 70 | entries = list(result['entries']) |
71 | self.assertTrue(len(entries) == 1) | |
72 | video = entries[0] | |
dd2a987d | 73 | self.assertEqual(video['_type'], 'url') |
bc2ca1bb | 74 | self.assertEqual(video['ie_key'], 'Youtube') |
75 | self.assertEqual(video['id'], 'BaW_jenozKc') | |
dd2a987d | 76 | self.assertEqual(video['url'], 'https://www.youtube.com/watch?v=BaW_jenozKc') |
bc2ca1bb | 77 | self.assertEqual(video['title'], 'youtube-dl test video "\'/\\ä↭𝕐') |
78 | self.assertEqual(video['duration'], 10) | |
79 | self.assertEqual(video['uploader'], 'Philipp Hagemeister') | |
8e5b1219 | 80 | |
582be358 | 81 | |
9789a05c FV |
82 | if __name__ == '__main__': |
83 | unittest.main() |