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