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.

70 lines
2.7 KiB

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