]> jfr.im git - yt-dlp.git/blob - test/test_youtube_lists.py
Update to ytdl-commit-78ce962
[yt-dlp.git] / test / test_youtube_lists.py
1 #!/usr/bin/env python3
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, is_download_test
11
12 from yt_dlp.extractor import (
13 YoutubeIE,
14 YoutubeTabIE,
15 )
16
17
18 @is_download_test
19 class TestYoutubeLists(unittest.TestCase):
20 def assertIsPlaylist(self, info):
21 """Make sure the info has '_type' set to 'playlist'"""
22 self.assertEqual(info['_type'], 'playlist')
23
24 def test_youtube_playlist_noplaylist(self):
25 dl = FakeYDL()
26 dl.params['noplaylist'] = True
27 ie = YoutubeTabIE(dl)
28 result = ie.extract('https://www.youtube.com/watch?v=OmJ-4B-mS-Y&list=PLydZ2Hrp_gPRJViZjLFKaBMgCQOYEEkyp&index=2')
29 self.assertEqual(result['_type'], 'url')
30 self.assertEqual(result['ie_key'], YoutubeIE.ie_key())
31 self.assertEqual(YoutubeIE.extract_id(result['url']), 'OmJ-4B-mS-Y')
32
33 def test_youtube_mix(self):
34 dl = FakeYDL()
35 ie = YoutubeTabIE(dl)
36 result = ie.extract('https://www.youtube.com/watch?v=tyITL_exICo&list=RDCLAK5uy_kLWIr9gv1XLlPbaDS965-Db4TrBoUTxQ8')
37 entries = list(result['entries'])
38 self.assertTrue(len(entries) >= 50)
39 original_video = entries[0]
40 self.assertEqual(original_video['id'], 'tyITL_exICo')
41
42 def test_youtube_flat_playlist_extraction(self):
43 dl = FakeYDL()
44 dl.params['extract_flat'] = True
45 ie = YoutubeTabIE(dl)
46 result = ie.extract('https://www.youtube.com/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc')
47 self.assertIsPlaylist(result)
48 entries = list(result['entries'])
49 self.assertTrue(len(entries) == 1)
50 video = entries[0]
51 self.assertEqual(video['_type'], 'url')
52 self.assertEqual(video['ie_key'], 'Youtube')
53 self.assertEqual(video['id'], 'BaW_jenozKc')
54 self.assertEqual(video['url'], 'https://www.youtube.com/watch?v=BaW_jenozKc')
55 self.assertEqual(video['title'], 'youtube-dl test video "\'/\\ä↭𝕐')
56 self.assertEqual(video['duration'], 10)
57 self.assertEqual(video['uploader'], 'Philipp Hagemeister')
58
59
60 if __name__ == '__main__':
61 unittest.main()