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.

57 lines
1.8 KiB

12 years ago
  1. #!/usr/bin/env python
  2. import sys
  3. import unittest
  4. import json
  5. import io
  6. import hashlib
  7. # Allow direct execution
  8. import os
  9. sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  10. from youtube_dl.InfoExtractors import YoutubeIE
  11. from youtube_dl.utils import *
  12. PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
  13. with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
  14. parameters = json.load(pf)
  15. # General configuration (from __init__, not very elegant...)
  16. jar = compat_cookiejar.CookieJar()
  17. cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
  18. proxy_handler = compat_urllib_request.ProxyHandler()
  19. opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
  20. compat_urllib_request.install_opener(opener)
  21. class FakeDownloader(object):
  22. def __init__(self):
  23. self.result = []
  24. self.params = parameters
  25. def to_screen(self, s):
  26. print(s)
  27. def trouble(self, s):
  28. raise Exception(s)
  29. def download(self, x):
  30. self.result.append(x)
  31. md5 = lambda s: hashlib.md5(s.encode('utf-8')).hexdigest()
  32. class TestYoutubeSubtitles(unittest.TestCase):
  33. def test_youtube_subtitles(self):
  34. DL = FakeDownloader()
  35. DL.params['writesubtitles'] = True
  36. IE = YoutubeIE(DL)
  37. info_dict = IE.extract('QRS8MkLhQmM')
  38. self.assertEqual(md5(info_dict[0]['subtitles']), 'c3228550d59116f3c29fba370b55d033')
  39. def test_youtube_subtitles_it(self):
  40. DL = FakeDownloader()
  41. DL.params['writesubtitles'] = True
  42. DL.params['subtitleslang'] = 'it'
  43. IE = YoutubeIE(DL)
  44. info_dict = IE.extract('QRS8MkLhQmM')
  45. self.assertEqual(md5(info_dict[0]['subtitles']), '132a88a0daf8e1520f393eb58f1f646a')
  46. if __name__ == '__main__':
  47. unittest.main()