]> Raphaƫl G. Git Repositories - youtubedl/blob - test/helper.py
debian/control: Make determination of python versions automatic.
[youtubedl] / test / helper.py
1 import io
2 import json
3 import os.path
4
5 from youtube_dl import YoutubeDL, YoutubeDLHandler
6 from youtube_dl.utils import (
7 compat_cookiejar,
8 compat_urllib_request,
9 )
10
11 # General configuration (from __init__, not very elegant...)
12 jar = compat_cookiejar.CookieJar()
13 cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
14 proxy_handler = compat_urllib_request.ProxyHandler()
15 opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
16 compat_urllib_request.install_opener(opener)
17
18 PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
19 with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
20 parameters = json.load(pf)
21
22 class FakeYDL(YoutubeDL):
23 def __init__(self):
24 self.result = []
25 # Different instances of the downloader can't share the same dictionary
26 # some test set the "sublang" parameter, which would break the md5 checks.
27 self.params = dict(parameters)
28 def to_screen(self, s):
29 print(s)
30 def trouble(self, s, tb=None):
31 raise Exception(s)
32 def download(self, x):
33 self.result.append(x)