]>
Commit | Line | Data |
---|---|---|
cc52de43 | 1 | #!/usr/bin/env python3 |
54007a45 | 2 | |
44a5f171 PH |
3 | # Allow direct execution |
4 | import os | |
9789a05c FV |
5 | import sys |
6 | import unittest | |
f8271158 | 7 | |
44a5f171 PH |
8 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
9 | ||
9789a05c | 10 | |
54007a45 | 11 | from test.helper import FakeYDL, is_download_test |
f8271158 | 12 | from yt_dlp.extractor import YoutubeIE, YoutubeTabIE |
86973308 | 13 | from yt_dlp.utils import ExtractorError |
9789a05c | 14 | |
9789a05c | 15 | |
060ac762 | 16 | @is_download_test |
9789a05c | 17 | class TestYoutubeLists(unittest.TestCase): |
44a5f171 | 18 | def assertIsPlaylist(self, info): |
8a38a194 JMF |
19 | """Make sure the info has '_type' set to 'playlist'""" |
20 | self.assertEqual(info['_type'], 'playlist') | |
21 | ||
d4d9920a FV |
22 | def test_youtube_playlist_noplaylist(self): |
23 | dl = FakeYDL() | |
24 | dl.params['noplaylist'] = True | |
dd2a987d | 25 | ie = YoutubeTabIE(dl) |
d5a39898 | 26 | result = ie.extract('https://www.youtube.com/watch?v=OmJ-4B-mS-Y&list=PLydZ2Hrp_gPRJViZjLFKaBMgCQOYEEkyp&index=2') |
d4d9920a | 27 | self.assertEqual(result['_type'], 'url') |
d5a39898 | 28 | self.assertEqual(result['ie_key'], YoutubeIE.ie_key()) |
29 | self.assertEqual(YoutubeIE.extract_id(result['url']), 'OmJ-4B-mS-Y') | |
9789a05c | 30 | |
652cdaa2 JMF |
31 | def test_youtube_mix(self): |
32 | dl = FakeYDL() | |
dd2a987d | 33 | ie = YoutubeTabIE(dl) |
34 | result = ie.extract('https://www.youtube.com/watch?v=tyITL_exICo&list=RDCLAK5uy_kLWIr9gv1XLlPbaDS965-Db4TrBoUTxQ8') | |
35 | entries = list(result['entries']) | |
1b6182d8 | 36 | self.assertTrue(len(entries) >= 50) |
652cdaa2 | 37 | original_video = entries[0] |
dd2a987d | 38 | self.assertEqual(original_video['id'], 'tyITL_exICo') |
652cdaa2 | 39 | |
bc2ca1bb | 40 | def test_youtube_flat_playlist_extraction(self): |
8e5b1219 S |
41 | dl = FakeYDL() |
42 | dl.params['extract_flat'] = True | |
bc2ca1bb | 43 | ie = YoutubeTabIE(dl) |
44 | result = ie.extract('https://www.youtube.com/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc') | |
8e5b1219 | 45 | self.assertIsPlaylist(result) |
bc2ca1bb | 46 | entries = list(result['entries']) |
47 | self.assertTrue(len(entries) == 1) | |
48 | video = entries[0] | |
dd2a987d | 49 | self.assertEqual(video['_type'], 'url') |
bc2ca1bb | 50 | self.assertEqual(video['ie_key'], 'Youtube') |
51 | self.assertEqual(video['id'], 'BaW_jenozKc') | |
dd2a987d | 52 | self.assertEqual(video['url'], 'https://www.youtube.com/watch?v=BaW_jenozKc') |
bc2ca1bb | 53 | self.assertEqual(video['title'], 'youtube-dl test video "\'/\\ä↭𝕐') |
54 | self.assertEqual(video['duration'], 10) | |
55 | self.assertEqual(video['uploader'], 'Philipp Hagemeister') | |
8e5b1219 | 56 | |
86973308 M |
57 | def test_youtube_channel_no_uploads(self): |
58 | dl = FakeYDL() | |
59 | dl.params['extract_flat'] = True | |
60 | ie = YoutubeTabIE(dl) | |
61 | # no uploads | |
62 | with self.assertRaisesRegex(ExtractorError, r'no uploads'): | |
63 | ie.extract('https://www.youtube.com/channel/UC2yXPzFejc422buOIzn_0CA') | |
64 | ||
65 | # no uploads and no UCID given | |
66 | with self.assertRaisesRegex(ExtractorError, r'no uploads'): | |
67 | ie.extract('https://www.youtube.com/news') | |
68 | ||
582be358 | 69 | |
9789a05c FV |
70 | if __name__ == '__main__': |
71 | unittest.main() |