3 # Allow direct execution
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
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
):
24 dl
.params
['noplaylist'] = True
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
):
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
):
42 dl
.params
['extract_flat'] = True
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)
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
):
59 dl
.params
['extract_flat'] = True
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__':