You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.1 KiB

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