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.

59 lines
1.9 KiB

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