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.

69 lines
2.5 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_writesubtitles(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_lang(self):
  33. self.DL.params['writesubtitles'] = True
  34. self.DL.params['subtitleslangs'] = ['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):
  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. def test_nosubtitles(self):
  51. self.url = 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
  52. self.DL.params['allsubtitles'] = True
  53. subtitles = self.getSubtitles()
  54. self.assertEqual(len(subtitles), 0)
  55. def test_multiple_langs(self):
  56. self.DL.params['writesubtitles'] = True
  57. langs = ['es', 'fr', 'de']
  58. self.DL.params['subtitleslangs'] = langs
  59. subtitles = self.getSubtitles()
  60. for lang in langs:
  61. self.assertTrue(subtitles.get(lang) is not None, u'Subtitles for \'%s\' not extracted' % lang)
  62. if __name__ == '__main__':
  63. unittest.main()