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.9 KiB

  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.extractor import DailymotionIE
  11. from youtube_dl.utils import *
  12. from helper import FakeYDL
  13. md5 = lambda s: hashlib.md5(s.encode('utf-8')).hexdigest()
  14. class TestDailymotionSubtitles(unittest.TestCase):
  15. def setUp(self):
  16. self.DL = FakeYDL()
  17. self.url = 'http://www.dailymotion.com/video/xczg00'
  18. def getInfoDict(self):
  19. IE = DailymotionIE(self.DL)
  20. info_dict = IE.extract(self.url)
  21. return info_dict
  22. def getSubtitles(self):
  23. info_dict = self.getInfoDict()
  24. return info_dict[0]['subtitles']
  25. def test_no_subtitles(self):
  26. subtitles = self.getSubtitles()
  27. self.assertEqual(subtitles, None)
  28. def test_subtitles(self):
  29. self.DL.params['writesubtitles'] = True
  30. subtitles = self.getSubtitles()
  31. self.assertEqual(md5(subtitles['en']), '976553874490cba125086bbfea3ff76f')
  32. def test_subtitles_fr(self):
  33. self.DL.params['writesubtitles'] = True
  34. self.DL.params['subtitleslang'] = 'fr'
  35. subtitles = self.getSubtitles()
  36. self.assertEqual(md5(subtitles['fr']), '594564ec7d588942e384e920e5341792')
  37. def test_allsubtitles(self):
  38. self.DL.params['allsubtitles'] = True
  39. subtitles = self.getSubtitles()
  40. self.assertEqual(len(subtitles.keys()), 5)
  41. def test_list_subtitles(self): #ojo
  42. self.DL.params['listsubtitles'] = True
  43. info_dict = self.getInfoDict()
  44. self.assertEqual(info_dict, None)
  45. def test_automatic_captions(self):
  46. self.DL.params['writeautomaticsub'] = True
  47. self.DL.params['subtitleslang'] = 'en'
  48. subtitles = self.getSubtitles()
  49. self.assertTrue(len(subtitles.keys()) == 0)
  50. if __name__ == '__main__':
  51. unittest.main()