]> jfr.im git - yt-dlp.git/blame - test/test_youtube_lists.py
Merge branch 'master' into extract_info_rewrite
[yt-dlp.git] / test / test_youtube_lists.py
CommitLineData
9789a05c
FV
1#!/usr/bin/env python
2
3import sys
4import unittest
5e5ddcfb 5import json
9789a05c
FV
6
7# Allow direct execution
8import os
9sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10
6324fd1d 11from youtube_dl.InfoExtractors import YoutubeUserIE, YoutubePlaylistIE, YoutubeIE
9789a05c
FV
12from youtube_dl.utils import *
13
5e5ddcfb
FV
14PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
15with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
16 parameters = json.load(pf)
17
9789a05c
FV
18# General configuration (from __init__, not very elegant...)
19jar = compat_cookiejar.CookieJar()
20cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
21proxy_handler = compat_urllib_request.ProxyHandler()
22opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
23compat_urllib_request.install_opener(opener)
9789a05c
FV
24
25class FakeDownloader(object):
26 def __init__(self):
27 self.result = []
5e5ddcfb 28 self.params = parameters
9789a05c
FV
29 def to_screen(self, s):
30 print(s)
31 def trouble(self, s):
32 raise Exception(s)
33 def download(self, x):
34 self.result.append(x)
35
36class TestYoutubeLists(unittest.TestCase):
37 def test_youtube_playlist(self):
679790ee
PH
38 dl = FakeDownloader()
39 ie = YoutubePlaylistIE(dl)
40 ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
acb8752f
PH
41 ytie_results = [YoutubeIE()._extract_id(r[0]) for r in dl.result]
42 self.assertEqual(ytie_results, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE'])
9789a05c 43
acb8752f 44 def test_issue_673(self):
679790ee
PH
45 dl = FakeDownloader()
46 ie = YoutubePlaylistIE(dl)
47 ie.extract('PLBB231211A4F62143')
48 self.assertTrue(len(dl.result) > 40)
89de9eb1 49
9789a05c 50 def test_youtube_playlist_long(self):
679790ee
PH
51 dl = FakeDownloader()
52 ie = YoutubePlaylistIE(dl)
53 ie.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
54 self.assertTrue(len(dl.result) >= 799)
9789a05c 55
6324fd1d 56 def test_youtube_playlist_with_deleted(self):
89de9eb1 57 #651
679790ee
PH
58 dl = FakeDownloader()
59 ie = YoutubePlaylistIE(dl)
60 ie.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
acb8752f
PH
61 ytie_results = [YoutubeIE()._extract_id(r[0]) for r in dl.result]
62 self.assertFalse('pElCt5oNDuI' in ytie_results)
63 self.assertFalse('KdPEApIVdWM' in ytie_results)
6324fd1d 64
9789a05c 65 def test_youtube_course(self):
679790ee
PH
66 dl = FakeDownloader()
67 ie = YoutubePlaylistIE(dl)
9789a05c 68 # TODO find a > 100 (paginating?) videos course
679790ee
PH
69 ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
70 self.assertEqual(YoutubeIE()._extract_id(dl.result[0][0]), 'j9WZyLZCBzs')
71 self.assertEqual(len(dl.result), 25)
72 self.assertEqual(YoutubeIE()._extract_id(dl.result[-1][0]), 'rYefUsYuEp0')
9789a05c
FV
73
74 def test_youtube_channel(self):
fd5ff020 75 # I give up, please find a channel that does paginate and test this like test_youtube_playlist_long
9789a05c
FV
76 pass # TODO
77
78 def test_youtube_user(self):
679790ee
PH
79 dl = FakeDownloader()
80 ie = YoutubeUserIE(dl)
81 ie.extract('https://www.youtube.com/user/TheLinuxFoundation')
82 self.assertTrue(len(dl.result) >= 320)
9789a05c
FV
83
84if __name__ == '__main__':
85 unittest.main()