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