Release 2024.11.18
[yt-dlp3.git] / test / test_youtube_lists.py
blobb3f323e21e52037fcc8f2a2b928ff38ee37e14ba
1 #!/usr/bin/env python3
3 # Allow direct execution
4 import os
5 import sys
6 import unittest
8 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
11 from test.helper import FakeYDL, is_download_test
12 from yt_dlp.extractor import YoutubeIE, YoutubeTabIE
13 from yt_dlp.utils import ExtractorError
16 @is_download_test
17 class TestYoutubeLists(unittest.TestCase):
18 def assertIsPlaylist(self, info):
19 """Make sure the info has '_type' set to 'playlist'"""
20 self.assertEqual(info['_type'], 'playlist')
22 def test_youtube_playlist_noplaylist(self):
23 dl = FakeYDL()
24 dl.params['noplaylist'] = True
25 ie = YoutubeTabIE(dl)
26 result = ie.extract('https://www.youtube.com/watch?v=OmJ-4B-mS-Y&list=PLydZ2Hrp_gPRJViZjLFKaBMgCQOYEEkyp&index=2')
27 self.assertEqual(result['_type'], 'url')
28 self.assertEqual(result['ie_key'], YoutubeIE.ie_key())
29 self.assertEqual(YoutubeIE.extract_id(result['url']), 'OmJ-4B-mS-Y')
31 def test_youtube_mix(self):
32 dl = FakeYDL()
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'])
36 self.assertTrue(len(entries) >= 50)
37 original_video = entries[0]
38 self.assertEqual(original_video['id'], 'tyITL_exICo')
40 def test_youtube_flat_playlist_extraction(self):
41 dl = FakeYDL()
42 dl.params['extract_flat'] = True
43 ie = YoutubeTabIE(dl)
44 result = ie.extract('https://www.youtube.com/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc')
45 self.assertIsPlaylist(result)
46 entries = list(result['entries'])
47 self.assertTrue(len(entries) == 1)
48 video = entries[0]
49 self.assertEqual(video['_type'], 'url')
50 self.assertEqual(video['ie_key'], 'Youtube')
51 self.assertEqual(video['id'], 'BaW_jenozKc')
52 self.assertEqual(video['url'], 'https://www.youtube.com/watch?v=BaW_jenozKc')
53 self.assertEqual(video['title'], 'youtube-dl test video "\'/\\ä↭𝕐')
54 self.assertEqual(video['duration'], 10)
55 self.assertEqual(video['uploader'], 'Philipp Hagemeister')
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')
65 # no uploads and no UCID given
66 with self.assertRaisesRegex(ExtractorError, r'no uploads'):
67 ie.extract('https://www.youtube.com/news')
70 if __name__ == '__main__':
71 unittest.main()