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.

71 lines
2.6 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['writesubtitles'] = True
  39. self.DL.params['allsubtitles'] = True
  40. subtitles = self.getSubtitles()
  41. self.assertEqual(len(subtitles.keys()), 5)
  42. def test_list_subtitles(self):
  43. self.DL.params['listsubtitles'] = True
  44. info_dict = self.getInfoDict()
  45. self.assertEqual(info_dict, None)
  46. def test_automatic_captions(self):
  47. self.DL.params['writeautomaticsub'] = True
  48. self.DL.params['subtitleslang'] = ['en']
  49. subtitles = self.getSubtitles()
  50. self.assertTrue(len(subtitles.keys()) == 0)
  51. def test_nosubtitles(self):
  52. self.url = 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
  53. self.DL.params['writesubtitles'] = True
  54. self.DL.params['allsubtitles'] = True
  55. subtitles = self.getSubtitles()
  56. self.assertEqual(len(subtitles), 0)
  57. def test_multiple_langs(self):
  58. self.DL.params['writesubtitles'] = True
  59. langs = ['es', 'fr', 'de']
  60. self.DL.params['subtitleslangs'] = langs
  61. subtitles = self.getSubtitles()
  62. for lang in langs:
  63. self.assertTrue(subtitles.get(lang) is not None, u'Subtitles for \'%s\' not extracted' % lang)
  64. if __name__ == '__main__':
  65. unittest.main()