]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_subtitles.py
2 from __future__
import unicode_literals
4 # Allow direct execution
8 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
10 from test
.helper
import FakeYDL
, md5
13 from youtube_dl
.extractor
import (
24 class BaseTestSubtitles(unittest
.TestCase
):
30 self
.ie
= self
.IE(self
.DL
)
32 def getInfoDict(self
):
33 info_dict
= self
.ie
.extract(self
.url
)
36 def getSubtitles(self
):
37 info_dict
= self
.getInfoDict()
38 return info_dict
['subtitles']
41 class TestYoutubeSubtitles(BaseTestSubtitles
):
45 def test_youtube_no_writesubtitles(self
):
46 self
.DL
.params
['writesubtitles'] = False
47 subtitles
= self
.getSubtitles()
48 self
.assertEqual(subtitles
, None)
50 def test_youtube_subtitles(self
):
51 self
.DL
.params
['writesubtitles'] = True
52 subtitles
= self
.getSubtitles()
53 self
.assertEqual(md5(subtitles
['en']), '4cd9278a35ba2305f47354ee13472260')
55 def test_youtube_subtitles_lang(self
):
56 self
.DL
.params
['writesubtitles'] = True
57 self
.DL
.params
['subtitleslangs'] = ['it']
58 subtitles
= self
.getSubtitles()
59 self
.assertEqual(md5(subtitles
['it']), '164a51f16f260476a05b50fe4c2f161d')
61 def test_youtube_allsubtitles(self
):
62 self
.DL
.params
['writesubtitles'] = True
63 self
.DL
.params
['allsubtitles'] = True
64 subtitles
= self
.getSubtitles()
65 self
.assertEqual(len(subtitles
.keys()), 13)
67 def test_youtube_subtitles_sbv_format(self
):
68 self
.DL
.params
['writesubtitles'] = True
69 self
.DL
.params
['subtitlesformat'] = 'sbv'
70 subtitles
= self
.getSubtitles()
71 self
.assertEqual(md5(subtitles
['en']), '13aeaa0c245a8bed9a451cb643e3ad8b')
73 def test_youtube_subtitles_vtt_format(self
):
74 self
.DL
.params
['writesubtitles'] = True
75 self
.DL
.params
['subtitlesformat'] = 'vtt'
76 subtitles
= self
.getSubtitles()
77 self
.assertEqual(md5(subtitles
['en']), '3cb210999d3e021bd6c7f0ea751eab06')
79 def test_youtube_list_subtitles(self
):
80 self
.DL
.expect_warning('Video doesn\'t have automatic captions')
81 self
.DL
.params
['listsubtitles'] = True
82 info_dict
= self
.getInfoDict()
83 self
.assertEqual(info_dict
, None)
85 def test_youtube_automatic_captions(self
):
86 self
.url
= '8YoUxe5ncPo'
87 self
.DL
.params
['writeautomaticsub'] = True
88 self
.DL
.params
['subtitleslangs'] = ['it']
89 subtitles
= self
.getSubtitles()
90 self
.assertTrue(subtitles
['it'] is not None)
92 def test_youtube_translated_subtitles(self
):
93 # This video has a subtitles track, which can be translated
94 self
.url
= 'Ky9eprVWzlI'
95 self
.DL
.params
['writeautomaticsub'] = True
96 self
.DL
.params
['subtitleslangs'] = ['it']
97 subtitles
= self
.getSubtitles()
98 self
.assertTrue(subtitles
['it'] is not None)
100 def test_youtube_nosubtitles(self
):
101 self
.DL
.expect_warning('video doesn\'t have subtitles')
102 self
.url
= 'n5BB19UTcdA'
103 self
.DL
.params
['writesubtitles'] = True
104 self
.DL
.params
['allsubtitles'] = True
105 subtitles
= self
.getSubtitles()
106 self
.assertEqual(len(subtitles
), 0)
108 def test_youtube_multiple_langs(self
):
109 self
.url
= 'QRS8MkLhQmM'
110 self
.DL
.params
['writesubtitles'] = True
111 langs
= ['it', 'fr', 'de']
112 self
.DL
.params
['subtitleslangs'] = langs
113 subtitles
= self
.getSubtitles()
115 self
.assertTrue(subtitles
.get(lang
) is not None, 'Subtitles for \'%s\' not extracted' % lang
)
118 class TestDailymotionSubtitles(BaseTestSubtitles
):
119 url
= 'http://www.dailymotion.com/video/xczg00'
122 def test_no_writesubtitles(self
):
123 subtitles
= self
.getSubtitles()
124 self
.assertEqual(subtitles
, None)
126 def test_subtitles(self
):
127 self
.DL
.params
['writesubtitles'] = True
128 subtitles
= self
.getSubtitles()
129 self
.assertEqual(md5(subtitles
['en']), '976553874490cba125086bbfea3ff76f')
131 def test_subtitles_lang(self
):
132 self
.DL
.params
['writesubtitles'] = True
133 self
.DL
.params
['subtitleslangs'] = ['fr']
134 subtitles
= self
.getSubtitles()
135 self
.assertEqual(md5(subtitles
['fr']), '594564ec7d588942e384e920e5341792')
137 def test_allsubtitles(self
):
138 self
.DL
.params
['writesubtitles'] = True
139 self
.DL
.params
['allsubtitles'] = True
140 subtitles
= self
.getSubtitles()
141 self
.assertEqual(len(subtitles
.keys()), 5)
143 def test_list_subtitles(self
):
144 self
.DL
.expect_warning('Automatic Captions not supported by this server')
145 self
.DL
.params
['listsubtitles'] = True
146 info_dict
= self
.getInfoDict()
147 self
.assertEqual(info_dict
, None)
149 def test_automatic_captions(self
):
150 self
.DL
.expect_warning('Automatic Captions not supported by this server')
151 self
.DL
.params
['writeautomaticsub'] = True
152 self
.DL
.params
['subtitleslang'] = ['en']
153 subtitles
= self
.getSubtitles()
154 self
.assertTrue(len(subtitles
.keys()) == 0)
156 def test_nosubtitles(self
):
157 self
.DL
.expect_warning('video doesn\'t have subtitles')
158 self
.url
= 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
159 self
.DL
.params
['writesubtitles'] = True
160 self
.DL
.params
['allsubtitles'] = True
161 subtitles
= self
.getSubtitles()
162 self
.assertEqual(len(subtitles
), 0)
164 def test_multiple_langs(self
):
165 self
.DL
.params
['writesubtitles'] = True
166 langs
= ['es', 'fr', 'de']
167 self
.DL
.params
['subtitleslangs'] = langs
168 subtitles
= self
.getSubtitles()
170 self
.assertTrue(subtitles
.get(lang
) is not None, 'Subtitles for \'%s\' not extracted' % lang
)
173 class TestTedSubtitles(BaseTestSubtitles
):
174 url
= 'http://www.ted.com/talks/dan_dennett_on_our_consciousness.html'
177 def test_no_writesubtitles(self
):
178 subtitles
= self
.getSubtitles()
179 self
.assertEqual(subtitles
, None)
181 def test_subtitles(self
):
182 self
.DL
.params
['writesubtitles'] = True
183 subtitles
= self
.getSubtitles()
184 self
.assertEqual(md5(subtitles
['en']), '4262c1665ff928a2dada178f62cb8d14')
186 def test_subtitles_lang(self
):
187 self
.DL
.params
['writesubtitles'] = True
188 self
.DL
.params
['subtitleslangs'] = ['fr']
189 subtitles
= self
.getSubtitles()
190 self
.assertEqual(md5(subtitles
['fr']), '66a63f7f42c97a50f8c0e90bc7797bb5')
192 def test_allsubtitles(self
):
193 self
.DL
.params
['writesubtitles'] = True
194 self
.DL
.params
['allsubtitles'] = True
195 subtitles
= self
.getSubtitles()
196 self
.assertTrue(len(subtitles
.keys()) >= 28)
198 def test_list_subtitles(self
):
199 self
.DL
.expect_warning('Automatic Captions not supported by this server')
200 self
.DL
.params
['listsubtitles'] = True
201 info_dict
= self
.getInfoDict()
202 self
.assertEqual(info_dict
, None)
204 def test_automatic_captions(self
):
205 self
.DL
.expect_warning('Automatic Captions not supported by this server')
206 self
.DL
.params
['writeautomaticsub'] = True
207 self
.DL
.params
['subtitleslang'] = ['en']
208 subtitles
= self
.getSubtitles()
209 self
.assertTrue(len(subtitles
.keys()) == 0)
211 def test_multiple_langs(self
):
212 self
.DL
.params
['writesubtitles'] = True
213 langs
= ['es', 'fr', 'de']
214 self
.DL
.params
['subtitleslangs'] = langs
215 subtitles
= self
.getSubtitles()
217 self
.assertTrue(subtitles
.get(lang
) is not None, 'Subtitles for \'%s\' not extracted' % lang
)
220 class TestBlipTVSubtitles(BaseTestSubtitles
):
221 url
= 'http://blip.tv/a/a-6603250'
224 def test_list_subtitles(self
):
225 self
.DL
.expect_warning('Automatic Captions not supported by this server')
226 self
.DL
.params
['listsubtitles'] = True
227 info_dict
= self
.getInfoDict()
228 self
.assertEqual(info_dict
, None)
230 def test_allsubtitles(self
):
231 self
.DL
.expect_warning('Automatic Captions not supported by this server')
232 self
.DL
.params
['writesubtitles'] = True
233 self
.DL
.params
['allsubtitles'] = True
234 subtitles
= self
.getSubtitles()
235 self
.assertEqual(set(subtitles
.keys()), set(['en']))
236 self
.assertEqual(md5(subtitles
['en']), '5b75c300af65fe4476dff79478bb93e4')
239 class TestVimeoSubtitles(BaseTestSubtitles
):
240 url
= 'http://vimeo.com/76979871'
243 def test_no_writesubtitles(self
):
244 subtitles
= self
.getSubtitles()
245 self
.assertEqual(subtitles
, None)
247 def test_subtitles(self
):
248 self
.DL
.params
['writesubtitles'] = True
249 subtitles
= self
.getSubtitles()
250 self
.assertEqual(md5(subtitles
['en']), '26399116d23ae3cf2c087cea94bc43b4')
252 def test_subtitles_lang(self
):
253 self
.DL
.params
['writesubtitles'] = True
254 self
.DL
.params
['subtitleslangs'] = ['fr']
255 subtitles
= self
.getSubtitles()
256 self
.assertEqual(md5(subtitles
['fr']), 'b6191146a6c5d3a452244d853fde6dc8')
258 def test_allsubtitles(self
):
259 self
.DL
.params
['writesubtitles'] = True
260 self
.DL
.params
['allsubtitles'] = True
261 subtitles
= self
.getSubtitles()
262 self
.assertEqual(set(subtitles
.keys()), set(['de', 'en', 'es', 'fr']))
264 def test_list_subtitles(self
):
265 self
.DL
.expect_warning('Automatic Captions not supported by this server')
266 self
.DL
.params
['listsubtitles'] = True
267 info_dict
= self
.getInfoDict()
268 self
.assertEqual(info_dict
, None)
270 def test_automatic_captions(self
):
271 self
.DL
.expect_warning('Automatic Captions not supported by this server')
272 self
.DL
.params
['writeautomaticsub'] = True
273 self
.DL
.params
['subtitleslang'] = ['en']
274 subtitles
= self
.getSubtitles()
275 self
.assertTrue(len(subtitles
.keys()) == 0)
277 def test_nosubtitles(self
):
278 self
.DL
.expect_warning('video doesn\'t have subtitles')
279 self
.url
= 'http://vimeo.com/56015672'
280 self
.DL
.params
['writesubtitles'] = True
281 self
.DL
.params
['allsubtitles'] = True
282 subtitles
= self
.getSubtitles()
283 self
.assertEqual(len(subtitles
), 0)
285 def test_multiple_langs(self
):
286 self
.DL
.params
['writesubtitles'] = True
287 langs
= ['es', 'fr', 'de']
288 self
.DL
.params
['subtitleslangs'] = langs
289 subtitles
= self
.getSubtitles()
291 self
.assertTrue(subtitles
.get(lang
) is not None, 'Subtitles for \'%s\' not extracted' % lang
)
294 class TestWallaSubtitles(BaseTestSubtitles
):
295 url
= 'http://vod.walla.co.il/movie/2705958/the-yes-men'
298 def test_list_subtitles(self
):
299 self
.DL
.expect_warning('Automatic Captions not supported by this server')
300 self
.DL
.params
['listsubtitles'] = True
301 info_dict
= self
.getInfoDict()
302 self
.assertEqual(info_dict
, None)
304 def test_allsubtitles(self
):
305 self
.DL
.expect_warning('Automatic Captions not supported by this server')
306 self
.DL
.params
['writesubtitles'] = True
307 self
.DL
.params
['allsubtitles'] = True
308 subtitles
= self
.getSubtitles()
309 self
.assertEqual(set(subtitles
.keys()), set(['heb']))
310 self
.assertEqual(md5(subtitles
['heb']), 'e758c5d7cb982f6bef14f377ec7a3920')
312 def test_nosubtitles(self
):
313 self
.DL
.expect_warning('video doesn\'t have subtitles')
314 self
.url
= 'http://vod.walla.co.il/movie/2642630/one-direction-all-for-one'
315 self
.DL
.params
['writesubtitles'] = True
316 self
.DL
.params
['allsubtitles'] = True
317 subtitles
= self
.getSubtitles()
318 self
.assertEqual(len(subtitles
), 0)
321 class TestCeskaTelevizeSubtitles(BaseTestSubtitles
):
322 url
= 'http://www.ceskatelevize.cz/ivysilani/10600540290-u6-uzasny-svet-techniky'
325 def test_list_subtitles(self
):
326 self
.DL
.expect_warning('Automatic Captions not supported by this server')
327 self
.DL
.params
['listsubtitles'] = True
328 info_dict
= self
.getInfoDict()
329 self
.assertEqual(info_dict
, None)
331 def test_allsubtitles(self
):
332 self
.DL
.expect_warning('Automatic Captions not supported by this server')
333 self
.DL
.params
['writesubtitles'] = True
334 self
.DL
.params
['allsubtitles'] = True
335 subtitles
= self
.getSubtitles()
336 self
.assertEqual(set(subtitles
.keys()), set(['cs']))
337 self
.assertEqual(md5(subtitles
['cs']), '9bf52d9549533c32c427e264bf0847d4')
339 def test_nosubtitles(self
):
340 self
.DL
.expect_warning('video doesn\'t have subtitles')
341 self
.url
= 'http://www.ceskatelevize.cz/ivysilani/ivysilani/10441294653-hyde-park-civilizace/214411058091220'
342 self
.DL
.params
['writesubtitles'] = True
343 self
.DL
.params
['allsubtitles'] = True
344 subtitles
= self
.getSubtitles()
345 self
.assertEqual(len(subtitles
), 0)
348 if __name__
== '__main__':