]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_subtitles.py
Record the explicit provenance of public domain status.
[youtubedl] / test / test_subtitles.py
1 #!/usr/bin/env python
2 from __future__ import unicode_literals
3
4 # Allow direct execution
5 import os
6 import sys
7 import unittest
8 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
10 from test.helper import FakeYDL, md5
11
12
13 from youtube_dl.extractor import (
14 BlipTVIE,
15 YoutubeIE,
16 DailymotionIE,
17 TEDIE,
18 VimeoIE,
19 WallaIE,
20 )
21
22
23 class BaseTestSubtitles(unittest.TestCase):
24 url = None
25 IE = None
26
27 def setUp(self):
28 self.DL = FakeYDL()
29 self.ie = self.IE(self.DL)
30
31 def getInfoDict(self):
32 info_dict = self.ie.extract(self.url)
33 return info_dict
34
35 def getSubtitles(self):
36 info_dict = self.getInfoDict()
37 return info_dict['subtitles']
38
39
40 class TestYoutubeSubtitles(BaseTestSubtitles):
41 url = 'QRS8MkLhQmM'
42 IE = YoutubeIE
43
44 def test_youtube_no_writesubtitles(self):
45 self.DL.params['writesubtitles'] = False
46 subtitles = self.getSubtitles()
47 self.assertEqual(subtitles, None)
48
49 def test_youtube_subtitles(self):
50 self.DL.params['writesubtitles'] = True
51 subtitles = self.getSubtitles()
52 self.assertEqual(md5(subtitles['en']), '4cd9278a35ba2305f47354ee13472260')
53
54 def test_youtube_subtitles_lang(self):
55 self.DL.params['writesubtitles'] = True
56 self.DL.params['subtitleslangs'] = ['it']
57 subtitles = self.getSubtitles()
58 self.assertEqual(md5(subtitles['it']), '164a51f16f260476a05b50fe4c2f161d')
59
60 def test_youtube_allsubtitles(self):
61 self.DL.params['writesubtitles'] = True
62 self.DL.params['allsubtitles'] = True
63 subtitles = self.getSubtitles()
64 self.assertEqual(len(subtitles.keys()), 13)
65
66 def test_youtube_subtitles_sbv_format(self):
67 self.DL.params['writesubtitles'] = True
68 self.DL.params['subtitlesformat'] = 'sbv'
69 subtitles = self.getSubtitles()
70 self.assertEqual(md5(subtitles['en']), '13aeaa0c245a8bed9a451cb643e3ad8b')
71
72 def test_youtube_subtitles_vtt_format(self):
73 self.DL.params['writesubtitles'] = True
74 self.DL.params['subtitlesformat'] = 'vtt'
75 subtitles = self.getSubtitles()
76 self.assertEqual(md5(subtitles['en']), '3cb210999d3e021bd6c7f0ea751eab06')
77
78 def test_youtube_list_subtitles(self):
79 self.DL.expect_warning('Video doesn\'t have automatic captions')
80 self.DL.params['listsubtitles'] = True
81 info_dict = self.getInfoDict()
82 self.assertEqual(info_dict, None)
83
84 def test_youtube_automatic_captions(self):
85 self.url = '8YoUxe5ncPo'
86 self.DL.params['writeautomaticsub'] = True
87 self.DL.params['subtitleslangs'] = ['it']
88 subtitles = self.getSubtitles()
89 self.assertTrue(subtitles['it'] is not None)
90
91 def test_youtube_nosubtitles(self):
92 self.DL.expect_warning('video doesn\'t have subtitles')
93 self.url = 'n5BB19UTcdA'
94 self.DL.params['writesubtitles'] = True
95 self.DL.params['allsubtitles'] = True
96 subtitles = self.getSubtitles()
97 self.assertEqual(len(subtitles), 0)
98
99 def test_youtube_multiple_langs(self):
100 self.url = 'QRS8MkLhQmM'
101 self.DL.params['writesubtitles'] = True
102 langs = ['it', 'fr', 'de']
103 self.DL.params['subtitleslangs'] = langs
104 subtitles = self.getSubtitles()
105 for lang in langs:
106 self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
107
108
109 class TestDailymotionSubtitles(BaseTestSubtitles):
110 url = 'http://www.dailymotion.com/video/xczg00'
111 IE = DailymotionIE
112
113 def test_no_writesubtitles(self):
114 subtitles = self.getSubtitles()
115 self.assertEqual(subtitles, None)
116
117 def test_subtitles(self):
118 self.DL.params['writesubtitles'] = True
119 subtitles = self.getSubtitles()
120 self.assertEqual(md5(subtitles['en']), '976553874490cba125086bbfea3ff76f')
121
122 def test_subtitles_lang(self):
123 self.DL.params['writesubtitles'] = True
124 self.DL.params['subtitleslangs'] = ['fr']
125 subtitles = self.getSubtitles()
126 self.assertEqual(md5(subtitles['fr']), '594564ec7d588942e384e920e5341792')
127
128 def test_allsubtitles(self):
129 self.DL.params['writesubtitles'] = True
130 self.DL.params['allsubtitles'] = True
131 subtitles = self.getSubtitles()
132 self.assertEqual(len(subtitles.keys()), 5)
133
134 def test_list_subtitles(self):
135 self.DL.expect_warning('Automatic Captions not supported by this server')
136 self.DL.params['listsubtitles'] = True
137 info_dict = self.getInfoDict()
138 self.assertEqual(info_dict, None)
139
140 def test_automatic_captions(self):
141 self.DL.expect_warning('Automatic Captions not supported by this server')
142 self.DL.params['writeautomaticsub'] = True
143 self.DL.params['subtitleslang'] = ['en']
144 subtitles = self.getSubtitles()
145 self.assertTrue(len(subtitles.keys()) == 0)
146
147 def test_nosubtitles(self):
148 self.DL.expect_warning('video doesn\'t have subtitles')
149 self.url = 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
150 self.DL.params['writesubtitles'] = True
151 self.DL.params['allsubtitles'] = True
152 subtitles = self.getSubtitles()
153 self.assertEqual(len(subtitles), 0)
154
155 def test_multiple_langs(self):
156 self.DL.params['writesubtitles'] = True
157 langs = ['es', 'fr', 'de']
158 self.DL.params['subtitleslangs'] = langs
159 subtitles = self.getSubtitles()
160 for lang in langs:
161 self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
162
163
164 class TestTedSubtitles(BaseTestSubtitles):
165 url = 'http://www.ted.com/talks/dan_dennett_on_our_consciousness.html'
166 IE = TEDIE
167
168 def test_no_writesubtitles(self):
169 subtitles = self.getSubtitles()
170 self.assertEqual(subtitles, None)
171
172 def test_subtitles(self):
173 self.DL.params['writesubtitles'] = True
174 subtitles = self.getSubtitles()
175 self.assertEqual(md5(subtitles['en']), '4262c1665ff928a2dada178f62cb8d14')
176
177 def test_subtitles_lang(self):
178 self.DL.params['writesubtitles'] = True
179 self.DL.params['subtitleslangs'] = ['fr']
180 subtitles = self.getSubtitles()
181 self.assertEqual(md5(subtitles['fr']), '66a63f7f42c97a50f8c0e90bc7797bb5')
182
183 def test_allsubtitles(self):
184 self.DL.params['writesubtitles'] = True
185 self.DL.params['allsubtitles'] = True
186 subtitles = self.getSubtitles()
187 self.assertTrue(len(subtitles.keys()) >= 28)
188
189 def test_list_subtitles(self):
190 self.DL.expect_warning('Automatic Captions not supported by this server')
191 self.DL.params['listsubtitles'] = True
192 info_dict = self.getInfoDict()
193 self.assertEqual(info_dict, None)
194
195 def test_automatic_captions(self):
196 self.DL.expect_warning('Automatic Captions not supported by this server')
197 self.DL.params['writeautomaticsub'] = True
198 self.DL.params['subtitleslang'] = ['en']
199 subtitles = self.getSubtitles()
200 self.assertTrue(len(subtitles.keys()) == 0)
201
202 def test_multiple_langs(self):
203 self.DL.params['writesubtitles'] = True
204 langs = ['es', 'fr', 'de']
205 self.DL.params['subtitleslangs'] = langs
206 subtitles = self.getSubtitles()
207 for lang in langs:
208 self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
209
210
211 class TestBlipTVSubtitles(BaseTestSubtitles):
212 url = 'http://blip.tv/a/a-6603250'
213 IE = BlipTVIE
214
215 def test_list_subtitles(self):
216 self.DL.expect_warning('Automatic Captions not supported by this server')
217 self.DL.params['listsubtitles'] = True
218 info_dict = self.getInfoDict()
219 self.assertEqual(info_dict, None)
220
221 def test_allsubtitles(self):
222 self.DL.expect_warning('Automatic Captions not supported by this server')
223 self.DL.params['writesubtitles'] = True
224 self.DL.params['allsubtitles'] = True
225 subtitles = self.getSubtitles()
226 self.assertEqual(set(subtitles.keys()), set(['en']))
227 self.assertEqual(md5(subtitles['en']), '5b75c300af65fe4476dff79478bb93e4')
228
229
230 class TestVimeoSubtitles(BaseTestSubtitles):
231 url = 'http://vimeo.com/76979871'
232 IE = VimeoIE
233
234 def test_no_writesubtitles(self):
235 subtitles = self.getSubtitles()
236 self.assertEqual(subtitles, None)
237
238 def test_subtitles(self):
239 self.DL.params['writesubtitles'] = True
240 subtitles = self.getSubtitles()
241 self.assertEqual(md5(subtitles['en']), '26399116d23ae3cf2c087cea94bc43b4')
242
243 def test_subtitles_lang(self):
244 self.DL.params['writesubtitles'] = True
245 self.DL.params['subtitleslangs'] = ['fr']
246 subtitles = self.getSubtitles()
247 self.assertEqual(md5(subtitles['fr']), 'b6191146a6c5d3a452244d853fde6dc8')
248
249 def test_allsubtitles(self):
250 self.DL.params['writesubtitles'] = True
251 self.DL.params['allsubtitles'] = True
252 subtitles = self.getSubtitles()
253 self.assertEqual(set(subtitles.keys()), set(['de', 'en', 'es', 'fr']))
254
255 def test_list_subtitles(self):
256 self.DL.expect_warning('Automatic Captions not supported by this server')
257 self.DL.params['listsubtitles'] = True
258 info_dict = self.getInfoDict()
259 self.assertEqual(info_dict, None)
260
261 def test_automatic_captions(self):
262 self.DL.expect_warning('Automatic Captions not supported by this server')
263 self.DL.params['writeautomaticsub'] = True
264 self.DL.params['subtitleslang'] = ['en']
265 subtitles = self.getSubtitles()
266 self.assertTrue(len(subtitles.keys()) == 0)
267
268 def test_nosubtitles(self):
269 self.DL.expect_warning('video doesn\'t have subtitles')
270 self.url = 'http://vimeo.com/56015672'
271 self.DL.params['writesubtitles'] = True
272 self.DL.params['allsubtitles'] = True
273 subtitles = self.getSubtitles()
274 self.assertEqual(len(subtitles), 0)
275
276 def test_multiple_langs(self):
277 self.DL.params['writesubtitles'] = True
278 langs = ['es', 'fr', 'de']
279 self.DL.params['subtitleslangs'] = langs
280 subtitles = self.getSubtitles()
281 for lang in langs:
282 self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
283
284
285 class TestWallaSubtitles(BaseTestSubtitles):
286 url = 'http://vod.walla.co.il/movie/2705958/the-yes-men'
287 IE = WallaIE
288
289 def test_list_subtitles(self):
290 self.DL.expect_warning('Automatic Captions not supported by this server')
291 self.DL.params['listsubtitles'] = True
292 info_dict = self.getInfoDict()
293 self.assertEqual(info_dict, None)
294
295 def test_allsubtitles(self):
296 self.DL.expect_warning('Automatic Captions not supported by this server')
297 self.DL.params['writesubtitles'] = True
298 self.DL.params['allsubtitles'] = True
299 subtitles = self.getSubtitles()
300 self.assertEqual(set(subtitles.keys()), set(['heb']))
301 self.assertEqual(md5(subtitles['heb']), 'e758c5d7cb982f6bef14f377ec7a3920')
302
303 def test_nosubtitles(self):
304 self.DL.expect_warning('video doesn\'t have subtitles')
305 self.url = 'http://vod.walla.co.il/movie/2642630/one-direction-all-for-one'
306 self.DL.params['writesubtitles'] = True
307 self.DL.params['allsubtitles'] = True
308 subtitles = self.getSubtitles()
309 self.assertEqual(len(subtitles), 0)
310
311
312 if __name__ == '__main__':
313 unittest.main()