]> jfr.im git - yt-dlp.git/blame - test/test_youtube_lists.py
fix playlist pagination and add YT playlist tests (closes #569)
[yt-dlp.git] / test / test_youtube_lists.py
CommitLineData
9789a05c
FV
1#!/usr/bin/env python
2
3import sys
4import unittest
5import socket
6
7# Allow direct execution
8import os
9sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10
11from youtube_dl.InfoExtractors import YoutubePlaylistIE
12from youtube_dl.utils import *
13
14# General configuration (from __init__, not very elegant...)
15jar = compat_cookiejar.CookieJar()
16cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
17proxy_handler = compat_urllib_request.ProxyHandler()
18opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
19compat_urllib_request.install_opener(opener)
20socket.setdefaulttimeout(300) # 5 minutes should be enough (famous last words)
21
22class FakeDownloader(object):
23 def __init__(self):
24 self.result = []
25 self.params = {}
26 def to_screen(self, s):
27 print(s)
28 def trouble(self, s):
29 raise Exception(s)
30 def download(self, x):
31 self.result.append(x)
32
33class TestYoutubeLists(unittest.TestCase):
34 def test_youtube_playlist(self):
35 DL = FakeDownloader()
36 IE = YoutubePlaylistIE(DL)
37 IE.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
38 self.assertEqual(DL.result, [
39 ['http://www.youtube.com/watch?v=bV9L5Ht9LgY'],
40 ['http://www.youtube.com/watch?v=FXxLjLQi3Fg'],
41 ['http://www.youtube.com/watch?v=tU3Bgo5qJZE']
42 ])
43
44 def test_youtube_playlist_long(self):
45 DL = FakeDownloader()
46 IE = YoutubePlaylistIE(DL)
47 IE.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
48 self.assertTrue(len(DL.result) >= 799)
49
50 def test_youtube_course(self):
51 DL = FakeDownloader()
52 IE = YoutubePlaylistIE(DL)
53 # TODO find a > 100 (paginating?) videos course
54 IE.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
55 self.assertEqual(DL.result[0], ['http://www.youtube.com/watch?v=j9WZyLZCBzs'])
56 self.assertEqual(len(DL.result), 25)
57 self.assertEqual(DL.result[-1], ['http://www.youtube.com/watch?v=rYefUsYuEp0'])
58
59 def test_youtube_channel(self):
60 """I give up, please find a channel that does paginate and test this like test_youtube_playlist_long"""
61 pass # TODO
62
63 def test_youtube_user(self):
64 DL = FakeDownloader()
65 IE = YoutubePlaylistIE(DL)
66 IE.extract('https://www.youtube.com/user/TheLinuxFoundation')
67 self.assertTrue(len(DL.result) >= 320)
68
69if __name__ == '__main__':
70 unittest.main()