]>
Commit | Line | Data |
---|---|---|
9789a05c FV |
1 | #!/usr/bin/env python |
2 | ||
3 | import sys | |
4 | import unittest | |
5e5ddcfb | 5 | import json |
9789a05c FV |
6 | |
7 | # Allow direct execution | |
8 | import os | |
9 | sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
10 | ||
2c6945be | 11 | from youtube_dl.InfoExtractors import YoutubeUserIE,YoutubePlaylistIE |
9789a05c FV |
12 | from youtube_dl.utils import * |
13 | ||
5e5ddcfb FV |
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) | |
17 | ||
9789a05c FV |
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) | |
9789a05c FV |
24 | |
25 | class 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 | ||
36 | class TestYoutubeLists(unittest.TestCase): | |
37 | def test_youtube_playlist(self): | |
38 | DL = FakeDownloader() | |
39 | IE = YoutubePlaylistIE(DL) | |
40 | IE.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re') | |
41 | self.assertEqual(DL.result, [ | |
42 | ['http://www.youtube.com/watch?v=bV9L5Ht9LgY'], | |
43 | ['http://www.youtube.com/watch?v=FXxLjLQi3Fg'], | |
44 | ['http://www.youtube.com/watch?v=tU3Bgo5qJZE'] | |
45 | ]) | |
46 | ||
47 | def test_youtube_playlist_long(self): | |
48 | DL = FakeDownloader() | |
49 | IE = YoutubePlaylistIE(DL) | |
50 | IE.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q') | |
51 | self.assertTrue(len(DL.result) >= 799) | |
52 | ||
53 | def test_youtube_course(self): | |
54 | DL = FakeDownloader() | |
55 | IE = YoutubePlaylistIE(DL) | |
56 | # TODO find a > 100 (paginating?) videos course | |
57 | IE.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8') | |
58 | self.assertEqual(DL.result[0], ['http://www.youtube.com/watch?v=j9WZyLZCBzs']) | |
59 | self.assertEqual(len(DL.result), 25) | |
60 | self.assertEqual(DL.result[-1], ['http://www.youtube.com/watch?v=rYefUsYuEp0']) | |
61 | ||
62 | def test_youtube_channel(self): | |
fd5ff020 | 63 | # I give up, please find a channel that does paginate and test this like test_youtube_playlist_long |
9789a05c FV |
64 | pass # TODO |
65 | ||
66 | def test_youtube_user(self): | |
67 | DL = FakeDownloader() | |
2c6945be | 68 | IE = YoutubeUserIE(DL) |
9789a05c FV |
69 | IE.extract('https://www.youtube.com/user/TheLinuxFoundation') |
70 | self.assertTrue(len(DL.result) >= 320) | |
71 | ||
72 | if __name__ == '__main__': | |
73 | unittest.main() |