7 # Allow direct execution
9 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
11 from youtube_dl.InfoExtractors import YoutubeUserIE, YoutubePlaylistIE, YoutubeIE
12 from youtube_dl.utils import *
14 PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
15 with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
16 parameters = json.load(pf)
18 # General configuration (from __init__, not very elegant...)
19 jar = compat_cookiejar.CookieJar()
20 cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
21 proxy_handler = compat_urllib_request.ProxyHandler()
22 opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
23 compat_urllib_request.install_opener(opener)
25 class FakeDownloader(object):
28 self.params = parameters
29 def to_screen(self, s):
33 def download(self, x):
36 class TestYoutubeLists(unittest.TestCase):
37 def test_youtube_playlist(self):
39 IE = YoutubePlaylistIE(DL)
40 IE.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
41 self.assertEqual(map(lambda x: YoutubeIE()._extract_id(x[0]), DL.result),
42 [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE' ])
46 IE = YoutubePlaylistIE(DL)
47 IE.extract('PLMCmkNmxw6Z9eduM7BZjSEh7HiU543Ig0')
48 self.assertTrue(len(DL.result) > 20)
52 IE = YoutubePlaylistIE(DL)
53 IE.extract('PLBB231211A4F62143')
54 self.assertTrue(len(DL.result) > 40)
56 def test_youtube_playlist_long(self):
58 IE = YoutubePlaylistIE(DL)
59 IE.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
60 self.assertTrue(len(DL.result) >= 799)
62 def test_youtube_playlist_with_deleted(self):
65 IE = YoutubePlaylistIE(DL)
66 IE.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
67 self.assertFalse('pElCt5oNDuI' in map(lambda x: YoutubeIE()._extract_id(x[0]), DL.result))
68 self.assertFalse('KdPEApIVdWM' in map(lambda x: YoutubeIE()._extract_id(x[0]), DL.result))
70 def test_youtube_course(self):
72 IE = YoutubePlaylistIE(DL)
73 # TODO find a > 100 (paginating?) videos course
74 IE.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
75 self.assertEqual(YoutubeIE()._extract_id(DL.result[0][0]), 'j9WZyLZCBzs')
76 self.assertEqual(len(DL.result), 25)
77 self.assertEqual(YoutubeIE()._extract_id(DL.result[-1][0]), 'rYefUsYuEp0')
79 def test_youtube_channel(self):
80 # I give up, please find a channel that does paginate and test this like test_youtube_playlist_long
83 def test_youtube_user(self):
85 IE = YoutubeUserIE(DL)
86 IE.extract('https://www.youtube.com/user/TheLinuxFoundation')
87 self.assertTrue(len(DL.result) >= 320)
89 if __name__ == '__main__':