]>
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 (
23 class BaseTestSubtitles(unittest
.TestCase
):
28 self
.ie
= self
.IE(self
.DL
)
30 def getInfoDict(self
):
31 info_dict
= self
.ie
.extract(self
.url
)
34 def getSubtitles(self
):
35 info_dict
= self
.getInfoDict()
36 return info_dict
['subtitles']
39 class TestYoutubeSubtitles(BaseTestSubtitles
):
43 def test_youtube_no_writesubtitles(self
):
44 self
.DL
.params
['writesubtitles'] = False
45 subtitles
= self
.getSubtitles()
46 self
.assertEqual(subtitles
, None)
48 def test_youtube_subtitles(self
):
49 self
.DL
.params
['writesubtitles'] = True
50 subtitles
= self
.getSubtitles()
51 self
.assertEqual(md5(subtitles
['en']), '4cd9278a35ba2305f47354ee13472260')
53 def test_youtube_subtitles_lang(self
):
54 self
.DL
.params
['writesubtitles'] = True
55 self
.DL
.params
['subtitleslangs'] = ['it']
56 subtitles
= self
.getSubtitles()
57 self
.assertEqual(md5(subtitles
['it']), '164a51f16f260476a05b50fe4c2f161d')
59 def test_youtube_allsubtitles(self
):
60 self
.DL
.params
['writesubtitles'] = True
61 self
.DL
.params
['allsubtitles'] = True
62 subtitles
= self
.getSubtitles()
63 self
.assertEqual(len(subtitles
.keys()), 13)
65 def test_youtube_subtitles_sbv_format(self
):
66 self
.DL
.params
['writesubtitles'] = True
67 self
.DL
.params
['subtitlesformat'] = 'sbv'
68 subtitles
= self
.getSubtitles()
69 self
.assertEqual(md5(subtitles
['en']), '13aeaa0c245a8bed9a451cb643e3ad8b')
71 def test_youtube_subtitles_vtt_format(self
):
72 self
.DL
.params
['writesubtitles'] = True
73 self
.DL
.params
['subtitlesformat'] = 'vtt'
74 subtitles
= self
.getSubtitles()
75 self
.assertEqual(md5(subtitles
['en']), '3cb210999d3e021bd6c7f0ea751eab06')
77 def test_youtube_list_subtitles(self
):
78 self
.DL
.expect_warning('Video doesn\'t have automatic captions')
79 self
.DL
.params
['listsubtitles'] = True
80 info_dict
= self
.getInfoDict()
81 self
.assertEqual(info_dict
, None)
83 def test_youtube_automatic_captions(self
):
84 self
.url
= '8YoUxe5ncPo'
85 self
.DL
.params
['writeautomaticsub'] = True
86 self
.DL
.params
['subtitleslangs'] = ['it']
87 subtitles
= self
.getSubtitles()
88 self
.assertTrue(subtitles
['it'] is not None)
90 def test_youtube_nosubtitles(self
):
91 self
.DL
.expect_warning('video doesn\'t have subtitles')
92 self
.url
= 'n5BB19UTcdA'
93 self
.DL
.params
['writesubtitles'] = True
94 self
.DL
.params
['allsubtitles'] = True
95 subtitles
= self
.getSubtitles()
96 self
.assertEqual(len(subtitles
), 0)
98 def test_youtube_multiple_langs(self
):
99 self
.url
= 'QRS8MkLhQmM'
100 self
.DL
.params
['writesubtitles'] = True
101 langs
= ['it', 'fr', 'de']
102 self
.DL
.params
['subtitleslangs'] = langs
103 subtitles
= self
.getSubtitles()
105 self
.assertTrue(subtitles
.get(lang
) is not None, 'Subtitles for \'%s\' not extracted' % lang
)
108 class TestDailymotionSubtitles(BaseTestSubtitles
):
109 url
= 'http://www.dailymotion.com/video/xczg00'
112 def test_no_writesubtitles(self
):
113 subtitles
= self
.getSubtitles()
114 self
.assertEqual(subtitles
, None)
116 def test_subtitles(self
):
117 self
.DL
.params
['writesubtitles'] = True
118 subtitles
= self
.getSubtitles()
119 self
.assertEqual(md5(subtitles
['en']), '976553874490cba125086bbfea3ff76f')
121 def test_subtitles_lang(self
):
122 self
.DL
.params
['writesubtitles'] = True
123 self
.DL
.params
['subtitleslangs'] = ['fr']
124 subtitles
= self
.getSubtitles()
125 self
.assertEqual(md5(subtitles
['fr']), '594564ec7d588942e384e920e5341792')
127 def test_allsubtitles(self
):
128 self
.DL
.params
['writesubtitles'] = True
129 self
.DL
.params
['allsubtitles'] = True
130 subtitles
= self
.getSubtitles()
131 self
.assertEqual(len(subtitles
.keys()), 5)
133 def test_list_subtitles(self
):
134 self
.DL
.expect_warning('Automatic Captions not supported by this server')
135 self
.DL
.params
['listsubtitles'] = True
136 info_dict
= self
.getInfoDict()
137 self
.assertEqual(info_dict
, None)
139 def test_automatic_captions(self
):
140 self
.DL
.expect_warning('Automatic Captions not supported by this server')
141 self
.DL
.params
['writeautomaticsub'] = True
142 self
.DL
.params
['subtitleslang'] = ['en']
143 subtitles
= self
.getSubtitles()
144 self
.assertTrue(len(subtitles
.keys()) == 0)
146 def test_nosubtitles(self
):
147 self
.DL
.expect_warning('video doesn\'t have subtitles')
148 self
.url
= 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
149 self
.DL
.params
['writesubtitles'] = True
150 self
.DL
.params
['allsubtitles'] = True
151 subtitles
= self
.getSubtitles()
152 self
.assertEqual(len(subtitles
), 0)
154 def test_multiple_langs(self
):
155 self
.DL
.params
['writesubtitles'] = True
156 langs
= ['es', 'fr', 'de']
157 self
.DL
.params
['subtitleslangs'] = langs
158 subtitles
= self
.getSubtitles()
160 self
.assertTrue(subtitles
.get(lang
) is not None, 'Subtitles for \'%s\' not extracted' % lang
)
163 class TestTedSubtitles(BaseTestSubtitles
):
164 url
= 'http://www.ted.com/talks/dan_dennett_on_our_consciousness.html'
167 def test_no_writesubtitles(self
):
168 subtitles
= self
.getSubtitles()
169 self
.assertEqual(subtitles
, None)
171 def test_subtitles(self
):
172 self
.DL
.params
['writesubtitles'] = True
173 subtitles
= self
.getSubtitles()
174 self
.assertEqual(md5(subtitles
['en']), '4262c1665ff928a2dada178f62cb8d14')
176 def test_subtitles_lang(self
):
177 self
.DL
.params
['writesubtitles'] = True
178 self
.DL
.params
['subtitleslangs'] = ['fr']
179 subtitles
= self
.getSubtitles()
180 self
.assertEqual(md5(subtitles
['fr']), '66a63f7f42c97a50f8c0e90bc7797bb5')
182 def test_allsubtitles(self
):
183 self
.DL
.params
['writesubtitles'] = True
184 self
.DL
.params
['allsubtitles'] = True
185 subtitles
= self
.getSubtitles()
186 self
.assertTrue(len(subtitles
.keys()) >= 28)
188 def test_list_subtitles(self
):
189 self
.DL
.expect_warning('Automatic Captions not supported by this server')
190 self
.DL
.params
['listsubtitles'] = True
191 info_dict
= self
.getInfoDict()
192 self
.assertEqual(info_dict
, None)
194 def test_automatic_captions(self
):
195 self
.DL
.expect_warning('Automatic Captions not supported by this server')
196 self
.DL
.params
['writeautomaticsub'] = True
197 self
.DL
.params
['subtitleslang'] = ['en']
198 subtitles
= self
.getSubtitles()
199 self
.assertTrue(len(subtitles
.keys()) == 0)
201 def test_multiple_langs(self
):
202 self
.DL
.params
['writesubtitles'] = True
203 langs
= ['es', 'fr', 'de']
204 self
.DL
.params
['subtitleslangs'] = langs
205 subtitles
= self
.getSubtitles()
207 self
.assertTrue(subtitles
.get(lang
) is not None, 'Subtitles for \'%s\' not extracted' % lang
)
210 class TestBlipTVSubtitles(BaseTestSubtitles
):
211 url
= 'http://blip.tv/a/a-6603250'
214 def test_list_subtitles(self
):
215 self
.DL
.expect_warning('Automatic Captions not supported by this server')
216 self
.DL
.params
['listsubtitles'] = True
217 info_dict
= self
.getInfoDict()
218 self
.assertEqual(info_dict
, None)
220 def test_allsubtitles(self
):
221 self
.DL
.expect_warning('Automatic Captions not supported by this server')
222 self
.DL
.params
['writesubtitles'] = True
223 self
.DL
.params
['allsubtitles'] = True
224 subtitles
= self
.getSubtitles()
225 self
.assertEqual(set(subtitles
.keys()), set(['en']))
226 self
.assertEqual(md5(subtitles
['en']), '5b75c300af65fe4476dff79478bb93e4')
229 class TestVimeoSubtitles(BaseTestSubtitles
):
230 url
= 'http://vimeo.com/76979871'
233 def test_no_writesubtitles(self
):
234 subtitles
= self
.getSubtitles()
235 self
.assertEqual(subtitles
, None)
237 def test_subtitles(self
):
238 self
.DL
.params
['writesubtitles'] = True
239 subtitles
= self
.getSubtitles()
240 self
.assertEqual(md5(subtitles
['en']), '8062383cf4dec168fc40a088aa6d5888')
242 def test_subtitles_lang(self
):
243 self
.DL
.params
['writesubtitles'] = True
244 self
.DL
.params
['subtitleslangs'] = ['fr']
245 subtitles
= self
.getSubtitles()
246 self
.assertEqual(md5(subtitles
['fr']), 'b6191146a6c5d3a452244d853fde6dc8')
248 def test_allsubtitles(self
):
249 self
.DL
.params
['writesubtitles'] = True
250 self
.DL
.params
['allsubtitles'] = True
251 subtitles
= self
.getSubtitles()
252 self
.assertEqual(set(subtitles
.keys()), set(['de', 'en', 'es', 'fr']))
254 def test_list_subtitles(self
):
255 self
.DL
.expect_warning('Automatic Captions not supported by this server')
256 self
.DL
.params
['listsubtitles'] = True
257 info_dict
= self
.getInfoDict()
258 self
.assertEqual(info_dict
, None)
260 def test_automatic_captions(self
):
261 self
.DL
.expect_warning('Automatic Captions not supported by this server')
262 self
.DL
.params
['writeautomaticsub'] = True
263 self
.DL
.params
['subtitleslang'] = ['en']
264 subtitles
= self
.getSubtitles()
265 self
.assertTrue(len(subtitles
.keys()) == 0)
267 def test_nosubtitles(self
):
268 self
.DL
.expect_warning('video doesn\'t have subtitles')
269 self
.url
= 'http://vimeo.com/56015672'
270 self
.DL
.params
['writesubtitles'] = True
271 self
.DL
.params
['allsubtitles'] = True
272 subtitles
= self
.getSubtitles()
273 self
.assertEqual(len(subtitles
), 0)
275 def test_multiple_langs(self
):
276 self
.DL
.params
['writesubtitles'] = True
277 langs
= ['es', 'fr', 'de']
278 self
.DL
.params
['subtitleslangs'] = langs
279 subtitles
= self
.getSubtitles()
281 self
.assertTrue(subtitles
.get(lang
) is not None, 'Subtitles for \'%s\' not extracted' % lang
)
284 class TestWallaSubtitles(BaseTestSubtitles
):
285 url
= 'http://vod.walla.co.il/movie/2705958/the-yes-men'
288 def test_list_subtitles(self
):
289 self
.DL
.expect_warning('Automatic Captions not supported by this server')
290 self
.DL
.params
['listsubtitles'] = True
291 info_dict
= self
.getInfoDict()
292 self
.assertEqual(info_dict
, None)
294 def test_allsubtitles(self
):
295 self
.DL
.expect_warning('Automatic Captions not supported by this server')
296 self
.DL
.params
['writesubtitles'] = True
297 self
.DL
.params
['allsubtitles'] = True
298 subtitles
= self
.getSubtitles()
299 self
.assertEqual(set(subtitles
.keys()), set(['heb']))
300 self
.assertEqual(md5(subtitles
['heb']), 'e758c5d7cb982f6bef14f377ec7a3920')
302 def test_nosubtitles(self
):
303 self
.DL
.expect_warning('video doesn\'t have subtitles')
304 self
.url
= 'http://vod.walla.co.il/movie/2642630/one-direction-all-for-one'
305 self
.DL
.params
['writesubtitles'] = True
306 self
.DL
.params
['allsubtitles'] = True
307 subtitles
= self
.getSubtitles()
308 self
.assertEqual(len(subtitles
), 0)
311 if __name__
== '__main__':