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.

44 lines
1.5 KiB

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