]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_dailymotion_subtitles.py
9 # Allow direct execution
11 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
13 from youtube_dl
.extractor
import DailymotionIE
14 from youtube_dl
.utils
import *
15 from helper
import FakeYDL
17 md5
= lambda s
: hashlib
.md5(s
.encode('utf-8')).hexdigest()
19 class TestDailymotionSubtitles(unittest
.TestCase
):
22 self
.url
= 'http://www.dailymotion.com/video/xczg00'
23 def getInfoDict(self
):
24 IE
= DailymotionIE(self
.DL
)
25 info_dict
= IE
.extract(self
.url
)
27 def getSubtitles(self
):
28 info_dict
= self
.getInfoDict()
29 return info_dict
[0]['subtitles']
30 def test_no_writesubtitles(self
):
31 subtitles
= self
.getSubtitles()
32 self
.assertEqual(subtitles
, None)
33 def test_subtitles(self
):
34 self
.DL
.params
['writesubtitles'] = True
35 subtitles
= self
.getSubtitles()
36 self
.assertEqual(md5(subtitles
['en']), '976553874490cba125086bbfea3ff76f')
37 def test_subtitles_lang(self
):
38 self
.DL
.params
['writesubtitles'] = True
39 self
.DL
.params
['subtitleslangs'] = ['fr']
40 subtitles
= self
.getSubtitles()
41 self
.assertEqual(md5(subtitles
['fr']), '594564ec7d588942e384e920e5341792')
42 def test_allsubtitles(self
):
43 self
.DL
.params
['writesubtitles'] = True
44 self
.DL
.params
['allsubtitles'] = True
45 subtitles
= self
.getSubtitles()
46 self
.assertEqual(len(subtitles
.keys()), 5)
47 def test_list_subtitles(self
):
48 self
.DL
.params
['listsubtitles'] = True
49 info_dict
= self
.getInfoDict()
50 self
.assertEqual(info_dict
, None)
51 def test_automatic_captions(self
):
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
.url
= 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
58 self
.DL
.params
['writesubtitles'] = True
59 self
.DL
.params
['allsubtitles'] = True
60 subtitles
= self
.getSubtitles()
61 self
.assertEqual(len(subtitles
), 0)
62 def test_multiple_langs(self
):
63 self
.DL
.params
['writesubtitles'] = True
64 langs
= ['es', 'fr', 'de']
65 self
.DL
.params
['subtitleslangs'] = langs
66 subtitles
= self
.getSubtitles()
68 self
.assertTrue(subtitles
.get(lang
) is not None, u
'Subtitles for \'%s\' not extracted' % lang
)
70 if __name__
== '__main__':