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.

72 lines
2.8 KiB

  1. #!/usr/bin/env python
  2. import sys
  3. import unittest
  4. import hashlib
  5. # Allow direct execution
  6. import os
  7. sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  8. from youtube_dl.extractor import DailymotionIE
  9. from youtube_dl.utils import *
  10. from .helper import FakeYDL
  11. md5 = lambda s: hashlib.md5(s.encode('utf-8')).hexdigest()
  12. class TestDailymotionSubtitles(unittest.TestCase):
  13. def setUp(self):
  14. self.DL = FakeYDL()
  15. self.url = 'http://www.dailymotion.com/video/xczg00'
  16. def getInfoDict(self):
  17. IE = DailymotionIE(self.DL)
  18. info_dict = IE.extract(self.url)
  19. return info_dict
  20. def getSubtitles(self):
  21. info_dict = self.getInfoDict()
  22. return info_dict[0]['subtitles']
  23. def test_no_writesubtitles(self):
  24. subtitles = self.getSubtitles()
  25. self.assertEqual(subtitles, None)
  26. def test_subtitles(self):
  27. self.DL.params['writesubtitles'] = True
  28. subtitles = self.getSubtitles()
  29. self.assertEqual(md5(subtitles['en']), '976553874490cba125086bbfea3ff76f')
  30. def test_subtitles_lang(self):
  31. self.DL.params['writesubtitles'] = True
  32. self.DL.params['subtitleslangs'] = ['fr']
  33. subtitles = self.getSubtitles()
  34. self.assertEqual(md5(subtitles['fr']), '594564ec7d588942e384e920e5341792')
  35. def test_allsubtitles(self):
  36. self.DL.params['writesubtitles'] = True
  37. self.DL.params['allsubtitles'] = True
  38. subtitles = self.getSubtitles()
  39. self.assertEqual(len(subtitles.keys()), 5)
  40. def test_list_subtitles(self):
  41. self.DL.expect_warning(u'Automatic Captions not supported by this server')
  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.expect_warning(u'Automatic Captions not supported by this server')
  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.DL.expect_warning(u'video doesn\'t have subtitles')
  53. self.url = 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
  54. self.DL.params['writesubtitles'] = True
  55. self.DL.params['allsubtitles'] = True
  56. subtitles = self.getSubtitles()
  57. self.assertEqual(len(subtitles), 0)
  58. def test_multiple_langs(self):
  59. self.DL.params['writesubtitles'] = True
  60. langs = ['es', 'fr', 'de']
  61. self.DL.params['subtitleslangs'] = langs
  62. subtitles = self.getSubtitles()
  63. for lang in langs:
  64. self.assertTrue(subtitles.get(lang) is not None, u'Subtitles for \'%s\' not extracted' % lang)
  65. if __name__ == '__main__':
  66. unittest.main()