]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_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
, md5
12 from youtube_dl
.extractor
import (
21 class BaseTestSubtitles(unittest
.TestCase
):
26 self
.ie
= self
.IE(self
.DL
)
28 def getInfoDict(self
):
29 info_dict
= self
.ie
.extract(self
.url
)
32 def getSubtitles(self
):
33 info_dict
= self
.getInfoDict()
34 return info_dict
['subtitles']
37 class TestYoutubeSubtitles(BaseTestSubtitles
):
41 def test_youtube_no_writesubtitles(self
):
42 self
.DL
.params
['writesubtitles'] = False
43 subtitles
= self
.getSubtitles()
44 self
.assertEqual(subtitles
, None)
46 def test_youtube_subtitles(self
):
47 self
.DL
.params
['writesubtitles'] = True
48 subtitles
= self
.getSubtitles()
49 self
.assertEqual(md5(subtitles
['en']), '4cd9278a35ba2305f47354ee13472260')
51 def test_youtube_subtitles_lang(self
):
52 self
.DL
.params
['writesubtitles'] = True
53 self
.DL
.params
['subtitleslangs'] = ['it']
54 subtitles
= self
.getSubtitles()
55 self
.assertEqual(md5(subtitles
['it']), '164a51f16f260476a05b50fe4c2f161d')
57 def test_youtube_allsubtitles(self
):
58 self
.DL
.params
['writesubtitles'] = True
59 self
.DL
.params
['allsubtitles'] = True
60 subtitles
= self
.getSubtitles()
61 self
.assertEqual(len(subtitles
.keys()), 13)
63 def test_youtube_subtitles_sbv_format(self
):
64 self
.DL
.params
['writesubtitles'] = True
65 self
.DL
.params
['subtitlesformat'] = 'sbv'
66 subtitles
= self
.getSubtitles()
67 self
.assertEqual(md5(subtitles
['en']), '13aeaa0c245a8bed9a451cb643e3ad8b')
69 def test_youtube_subtitles_vtt_format(self
):
70 self
.DL
.params
['writesubtitles'] = True
71 self
.DL
.params
['subtitlesformat'] = 'vtt'
72 subtitles
= self
.getSubtitles()
73 self
.assertEqual(md5(subtitles
['en']), '3cb210999d3e021bd6c7f0ea751eab06')
75 def test_youtube_list_subtitles(self
):
76 self
.DL
.expect_warning(u
'Video doesn\'t have automatic captions')
77 self
.DL
.params
['listsubtitles'] = True
78 info_dict
= self
.getInfoDict()
79 self
.assertEqual(info_dict
, None)
81 def test_youtube_automatic_captions(self
):
82 self
.url
= '8YoUxe5ncPo'
83 self
.DL
.params
['writeautomaticsub'] = True
84 self
.DL
.params
['subtitleslangs'] = ['it']
85 subtitles
= self
.getSubtitles()
86 self
.assertTrue(subtitles
['it'] is not None)
88 def test_youtube_nosubtitles(self
):
89 self
.DL
.expect_warning(u
'video doesn\'t have subtitles')
90 self
.url
= 'sAjKT8FhjI8'
91 self
.DL
.params
['writesubtitles'] = True
92 self
.DL
.params
['allsubtitles'] = True
93 subtitles
= self
.getSubtitles()
94 self
.assertEqual(len(subtitles
), 0)
96 def test_youtube_multiple_langs(self
):
97 self
.url
= 'QRS8MkLhQmM'
98 self
.DL
.params
['writesubtitles'] = True
99 langs
= ['it', 'fr', 'de']
100 self
.DL
.params
['subtitleslangs'] = langs
101 subtitles
= self
.getSubtitles()
103 self
.assertTrue(subtitles
.get(lang
) is not None, u
'Subtitles for \'%s\' not extracted' % lang
)
106 class TestDailymotionSubtitles(BaseTestSubtitles
):
107 url
= 'http://www.dailymotion.com/video/xczg00'
110 def test_no_writesubtitles(self
):
111 subtitles
= self
.getSubtitles()
112 self
.assertEqual(subtitles
, None)
114 def test_subtitles(self
):
115 self
.DL
.params
['writesubtitles'] = True
116 subtitles
= self
.getSubtitles()
117 self
.assertEqual(md5(subtitles
['en']), '976553874490cba125086bbfea3ff76f')
119 def test_subtitles_lang(self
):
120 self
.DL
.params
['writesubtitles'] = True
121 self
.DL
.params
['subtitleslangs'] = ['fr']
122 subtitles
= self
.getSubtitles()
123 self
.assertEqual(md5(subtitles
['fr']), '594564ec7d588942e384e920e5341792')
125 def test_allsubtitles(self
):
126 self
.DL
.params
['writesubtitles'] = True
127 self
.DL
.params
['allsubtitles'] = True
128 subtitles
= self
.getSubtitles()
129 self
.assertEqual(len(subtitles
.keys()), 5)
131 def test_list_subtitles(self
):
132 self
.DL
.expect_warning(u
'Automatic Captions not supported by this server')
133 self
.DL
.params
['listsubtitles'] = True
134 info_dict
= self
.getInfoDict()
135 self
.assertEqual(info_dict
, None)
137 def test_automatic_captions(self
):
138 self
.DL
.expect_warning(u
'Automatic Captions not supported by this server')
139 self
.DL
.params
['writeautomaticsub'] = True
140 self
.DL
.params
['subtitleslang'] = ['en']
141 subtitles
= self
.getSubtitles()
142 self
.assertTrue(len(subtitles
.keys()) == 0)
144 def test_nosubtitles(self
):
145 self
.DL
.expect_warning(u
'video doesn\'t have subtitles')
146 self
.url
= 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
147 self
.DL
.params
['writesubtitles'] = True
148 self
.DL
.params
['allsubtitles'] = True
149 subtitles
= self
.getSubtitles()
150 self
.assertEqual(len(subtitles
), 0)
152 def test_multiple_langs(self
):
153 self
.DL
.params
['writesubtitles'] = True
154 langs
= ['es', 'fr', 'de']
155 self
.DL
.params
['subtitleslangs'] = langs
156 subtitles
= self
.getSubtitles()
158 self
.assertTrue(subtitles
.get(lang
) is not None, u
'Subtitles for \'%s\' not extracted' % lang
)
161 class TestTedSubtitles(BaseTestSubtitles
):
162 url
= 'http://www.ted.com/talks/dan_dennett_on_our_consciousness.html'
165 def test_no_writesubtitles(self
):
166 subtitles
= self
.getSubtitles()
167 self
.assertEqual(subtitles
, None)
169 def test_subtitles(self
):
170 self
.DL
.params
['writesubtitles'] = True
171 subtitles
= self
.getSubtitles()
172 self
.assertEqual(md5(subtitles
['en']), '4262c1665ff928a2dada178f62cb8d14')
174 def test_subtitles_lang(self
):
175 self
.DL
.params
['writesubtitles'] = True
176 self
.DL
.params
['subtitleslangs'] = ['fr']
177 subtitles
= self
.getSubtitles()
178 self
.assertEqual(md5(subtitles
['fr']), '66a63f7f42c97a50f8c0e90bc7797bb5')
180 def test_allsubtitles(self
):
181 self
.DL
.params
['writesubtitles'] = True
182 self
.DL
.params
['allsubtitles'] = True
183 subtitles
= self
.getSubtitles()
184 self
.assertEqual(len(subtitles
.keys()), 28)
186 def test_list_subtitles(self
):
187 self
.DL
.expect_warning(u
'Automatic Captions not supported by this server')
188 self
.DL
.params
['listsubtitles'] = True
189 info_dict
= self
.getInfoDict()
190 self
.assertEqual(info_dict
, None)
192 def test_automatic_captions(self
):
193 self
.DL
.expect_warning(u
'Automatic Captions not supported by this server')
194 self
.DL
.params
['writeautomaticsub'] = True
195 self
.DL
.params
['subtitleslang'] = ['en']
196 subtitles
= self
.getSubtitles()
197 self
.assertTrue(len(subtitles
.keys()) == 0)
199 def test_multiple_langs(self
):
200 self
.DL
.params
['writesubtitles'] = True
201 langs
= ['es', 'fr', 'de']
202 self
.DL
.params
['subtitleslangs'] = langs
203 subtitles
= self
.getSubtitles()
205 self
.assertTrue(subtitles
.get(lang
) is not None, u
'Subtitles for \'%s\' not extracted' % lang
)
208 class TestBlipTVSubtitles(BaseTestSubtitles
):
209 url
= 'http://blip.tv/a/a-6603250'
212 def test_list_subtitles(self
):
213 self
.DL
.expect_warning(u
'Automatic Captions not supported by this server')
214 self
.DL
.params
['listsubtitles'] = True
215 info_dict
= self
.getInfoDict()
216 self
.assertEqual(info_dict
, None)
218 def test_allsubtitles(self
):
219 self
.DL
.expect_warning(u
'Automatic Captions not supported by this server')
220 self
.DL
.params
['writesubtitles'] = True
221 self
.DL
.params
['allsubtitles'] = True
222 subtitles
= self
.getSubtitles()
223 self
.assertEqual(set(subtitles
.keys()), set(['en']))
224 self
.assertEqual(md5(subtitles
['en']), '5b75c300af65fe4476dff79478bb93e4')
227 class TestVimeoSubtitles(BaseTestSubtitles
):
228 url
= 'http://vimeo.com/76979871'
231 def test_no_writesubtitles(self
):
232 subtitles
= self
.getSubtitles()
233 self
.assertEqual(subtitles
, None)
235 def test_subtitles(self
):
236 self
.DL
.params
['writesubtitles'] = True
237 subtitles
= self
.getSubtitles()
238 self
.assertEqual(md5(subtitles
['en']), '8062383cf4dec168fc40a088aa6d5888')
240 def test_subtitles_lang(self
):
241 self
.DL
.params
['writesubtitles'] = True
242 self
.DL
.params
['subtitleslangs'] = ['fr']
243 subtitles
= self
.getSubtitles()
244 self
.assertEqual(md5(subtitles
['fr']), 'b6191146a6c5d3a452244d853fde6dc8')
246 def test_allsubtitles(self
):
247 self
.DL
.params
['writesubtitles'] = True
248 self
.DL
.params
['allsubtitles'] = True
249 subtitles
= self
.getSubtitles()
250 self
.assertEqual(set(subtitles
.keys()), set(['de', 'en', 'es', 'fr']))
252 def test_list_subtitles(self
):
253 self
.DL
.expect_warning(u
'Automatic Captions not supported by this server')
254 self
.DL
.params
['listsubtitles'] = True
255 info_dict
= self
.getInfoDict()
256 self
.assertEqual(info_dict
, None)
258 def test_automatic_captions(self
):
259 self
.DL
.expect_warning(u
'Automatic Captions not supported by this server')
260 self
.DL
.params
['writeautomaticsub'] = True
261 self
.DL
.params
['subtitleslang'] = ['en']
262 subtitles
= self
.getSubtitles()
263 self
.assertTrue(len(subtitles
.keys()) == 0)
265 def test_nosubtitles(self
):
266 self
.DL
.expect_warning(u
'video doesn\'t have subtitles')
267 self
.url
= 'http://vimeo.com/56015672'
268 self
.DL
.params
['writesubtitles'] = True
269 self
.DL
.params
['allsubtitles'] = True
270 subtitles
= self
.getSubtitles()
271 self
.assertEqual(len(subtitles
), 0)
273 def test_multiple_langs(self
):
274 self
.DL
.params
['writesubtitles'] = True
275 langs
= ['es', 'fr', 'de']
276 self
.DL
.params
['subtitleslangs'] = langs
277 subtitles
= self
.getSubtitles()
279 self
.assertTrue(subtitles
.get(lang
) is not None, u
'Subtitles for \'%s\' not extracted' % lang
)
282 if __name__
== '__main__':