7 import youtube_dl.extractor
8 from youtube_dl import YoutubeDL, YoutubeDLHandler
9 from youtube_dl.utils import (
11 compat_urllib_request,
14 # General configuration (from __init__, not very elegant...)
15 jar = compat_cookiejar.CookieJar()
16 cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
17 proxy_handler = compat_urllib_request.ProxyHandler()
18 opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
19 compat_urllib_request.install_opener(opener)
21 PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
22 with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
23 parameters = json.load(pf)
25 class FakeYDL(YoutubeDL):
28 # Different instances of the downloader can't share the same dictionary
29 # some test set the "sublang" parameter, which would break the md5 checks.
30 self.params = dict(parameters)
31 def to_screen(self, s):
33 def trouble(self, s, tb=None):
35 def download(self, x):
37 def expect_warning(self, regex):
38 # Silence an expected warning matching a regex
39 old_report_warning = self.report_warning
40 def report_warning(self, message):
41 if re.match(regex, message): return
42 old_report_warning(message)
43 self.report_warning = types.MethodType(report_warning, self)
46 for ie in youtube_dl.extractor.gen_extractors():
47 t = getattr(ie, '_TEST', None)
49 t['name'] = type(ie).__name__[:-len('IE')]
51 for t in getattr(ie, '_TESTS', []):
52 t['name'] = type(ie).__name__[:-len('IE')]