]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_subtitles.py
Imported Upstream version 2015.11.27.1
[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 CeskaTelevizeIE,
21 LyndaIE,
22 NPOIE,
23 ComedyCentralIE,
24 NRKTVIE,
25 RaiIE,
26 VikiIE,
27 ThePlatformIE,
28 ThePlatformFeedIE,
29 RTVEALaCartaIE,
30 FunnyOrDieIE,
31 DemocracynowIE,
32 )
33
34
35 class BaseTestSubtitles(unittest.TestCase):
36 url = None
37 IE = None
38
39 def setUp(self):
40 self.DL = FakeYDL()
41 self.ie = self.IE()
42 self.DL.add_info_extractor(self.ie)
43
44 def getInfoDict(self):
45 info_dict = self.DL.extract_info(self.url, download=False)
46 return info_dict
47
48 def getSubtitles(self):
49 info_dict = self.getInfoDict()
50 subtitles = info_dict['requested_subtitles']
51 if not subtitles:
52 return subtitles
53 for sub_info in subtitles.values():
54 if sub_info.get('data') is None:
55 uf = self.DL.urlopen(sub_info['url'])
56 sub_info['data'] = uf.read().decode('utf-8')
57 return dict((l, sub_info['data']) for l, sub_info in subtitles.items())
58
59
60 class TestYoutubeSubtitles(BaseTestSubtitles):
61 url = 'QRS8MkLhQmM'
62 IE = YoutubeIE
63
64 def test_youtube_allsubtitles(self):
65 self.DL.params['writesubtitles'] = True
66 self.DL.params['allsubtitles'] = True
67 subtitles = self.getSubtitles()
68 self.assertEqual(len(subtitles.keys()), 13)
69 self.assertEqual(md5(subtitles['en']), '4cd9278a35ba2305f47354ee13472260')
70 self.assertEqual(md5(subtitles['it']), '164a51f16f260476a05b50fe4c2f161d')
71 for lang in ['it', 'fr', 'de']:
72 self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
73
74 def test_youtube_subtitles_sbv_format(self):
75 self.DL.params['writesubtitles'] = True
76 self.DL.params['subtitlesformat'] = 'sbv'
77 subtitles = self.getSubtitles()
78 self.assertEqual(md5(subtitles['en']), '13aeaa0c245a8bed9a451cb643e3ad8b')
79
80 def test_youtube_subtitles_vtt_format(self):
81 self.DL.params['writesubtitles'] = True
82 self.DL.params['subtitlesformat'] = 'vtt'
83 subtitles = self.getSubtitles()
84 self.assertEqual(md5(subtitles['en']), '3cb210999d3e021bd6c7f0ea751eab06')
85
86 def test_youtube_automatic_captions(self):
87 self.url = '8YoUxe5ncPo'
88 self.DL.params['writeautomaticsub'] = True
89 self.DL.params['subtitleslangs'] = ['it']
90 subtitles = self.getSubtitles()
91 self.assertTrue(subtitles['it'] is not None)
92
93 def test_youtube_translated_subtitles(self):
94 # This video has a subtitles track, which can be translated
95 self.url = 'Ky9eprVWzlI'
96 self.DL.params['writeautomaticsub'] = True
97 self.DL.params['subtitleslangs'] = ['it']
98 subtitles = self.getSubtitles()
99 self.assertTrue(subtitles['it'] is not None)
100
101 def test_youtube_nosubtitles(self):
102 self.DL.expect_warning('video doesn\'t have subtitles')
103 self.url = 'n5BB19UTcdA'
104 self.DL.params['writesubtitles'] = True
105 self.DL.params['allsubtitles'] = True
106 subtitles = self.getSubtitles()
107 self.assertFalse(subtitles)
108
109
110 class TestDailymotionSubtitles(BaseTestSubtitles):
111 url = 'http://www.dailymotion.com/video/xczg00'
112 IE = DailymotionIE
113
114 def test_allsubtitles(self):
115 self.DL.params['writesubtitles'] = True
116 self.DL.params['allsubtitles'] = True
117 subtitles = self.getSubtitles()
118 self.assertTrue(len(subtitles.keys()) >= 6)
119 self.assertEqual(md5(subtitles['en']), '976553874490cba125086bbfea3ff76f')
120 self.assertEqual(md5(subtitles['fr']), '594564ec7d588942e384e920e5341792')
121 for lang in ['es', 'fr', 'de']:
122 self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
123
124 def test_nosubtitles(self):
125 self.DL.expect_warning('video doesn\'t have subtitles')
126 self.url = 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
127 self.DL.params['writesubtitles'] = True
128 self.DL.params['allsubtitles'] = True
129 subtitles = self.getSubtitles()
130 self.assertFalse(subtitles)
131
132
133 class TestTedSubtitles(BaseTestSubtitles):
134 url = 'http://www.ted.com/talks/dan_dennett_on_our_consciousness.html'
135 IE = TEDIE
136
137 def test_allsubtitles(self):
138 self.DL.params['writesubtitles'] = True
139 self.DL.params['allsubtitles'] = True
140 subtitles = self.getSubtitles()
141 self.assertTrue(len(subtitles.keys()) >= 28)
142 self.assertEqual(md5(subtitles['en']), '4262c1665ff928a2dada178f62cb8d14')
143 self.assertEqual(md5(subtitles['fr']), '66a63f7f42c97a50f8c0e90bc7797bb5')
144 for lang in ['es', 'fr', 'de']:
145 self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
146
147
148 class TestBlipTVSubtitles(BaseTestSubtitles):
149 url = 'http://blip.tv/a/a-6603250'
150 IE = BlipTVIE
151
152 def test_allsubtitles(self):
153 self.DL.params['writesubtitles'] = True
154 self.DL.params['allsubtitles'] = True
155 subtitles = self.getSubtitles()
156 self.assertEqual(set(subtitles.keys()), set(['en']))
157 self.assertEqual(md5(subtitles['en']), '5b75c300af65fe4476dff79478bb93e4')
158
159
160 class TestVimeoSubtitles(BaseTestSubtitles):
161 url = 'http://vimeo.com/76979871'
162 IE = VimeoIE
163
164 def test_allsubtitles(self):
165 self.DL.params['writesubtitles'] = True
166 self.DL.params['allsubtitles'] = True
167 subtitles = self.getSubtitles()
168 self.assertEqual(set(subtitles.keys()), set(['de', 'en', 'es', 'fr']))
169 self.assertEqual(md5(subtitles['en']), '8062383cf4dec168fc40a088aa6d5888')
170 self.assertEqual(md5(subtitles['fr']), 'b6191146a6c5d3a452244d853fde6dc8')
171
172 def test_nosubtitles(self):
173 self.DL.expect_warning('video doesn\'t have subtitles')
174 self.url = 'http://vimeo.com/56015672'
175 self.DL.params['writesubtitles'] = True
176 self.DL.params['allsubtitles'] = True
177 subtitles = self.getSubtitles()
178 self.assertFalse(subtitles)
179
180
181 class TestWallaSubtitles(BaseTestSubtitles):
182 url = 'http://vod.walla.co.il/movie/2705958/the-yes-men'
183 IE = WallaIE
184
185 def test_allsubtitles(self):
186 self.DL.expect_warning('Automatic Captions not supported by this server')
187 self.DL.params['writesubtitles'] = True
188 self.DL.params['allsubtitles'] = True
189 subtitles = self.getSubtitles()
190 self.assertEqual(set(subtitles.keys()), set(['heb']))
191 self.assertEqual(md5(subtitles['heb']), 'e758c5d7cb982f6bef14f377ec7a3920')
192
193 def test_nosubtitles(self):
194 self.DL.expect_warning('video doesn\'t have subtitles')
195 self.url = 'http://vod.walla.co.il/movie/2642630/one-direction-all-for-one'
196 self.DL.params['writesubtitles'] = True
197 self.DL.params['allsubtitles'] = True
198 subtitles = self.getSubtitles()
199 self.assertFalse(subtitles)
200
201
202 class TestCeskaTelevizeSubtitles(BaseTestSubtitles):
203 url = 'http://www.ceskatelevize.cz/ivysilani/10600540290-u6-uzasny-svet-techniky'
204 IE = CeskaTelevizeIE
205
206 def test_allsubtitles(self):
207 self.DL.expect_warning('Automatic Captions not supported by this server')
208 self.DL.params['writesubtitles'] = True
209 self.DL.params['allsubtitles'] = True
210 subtitles = self.getSubtitles()
211 self.assertEqual(set(subtitles.keys()), set(['cs']))
212 self.assertTrue(len(subtitles['cs']) > 20000)
213
214 def test_nosubtitles(self):
215 self.DL.expect_warning('video doesn\'t have subtitles')
216 self.url = 'http://www.ceskatelevize.cz/ivysilani/ivysilani/10441294653-hyde-park-civilizace/214411058091220'
217 self.DL.params['writesubtitles'] = True
218 self.DL.params['allsubtitles'] = True
219 subtitles = self.getSubtitles()
220 self.assertFalse(subtitles)
221
222
223 class TestLyndaSubtitles(BaseTestSubtitles):
224 url = 'http://www.lynda.com/Bootstrap-tutorials/Using-exercise-files/110885/114408-4.html'
225 IE = LyndaIE
226
227 def test_allsubtitles(self):
228 self.DL.params['writesubtitles'] = True
229 self.DL.params['allsubtitles'] = True
230 subtitles = self.getSubtitles()
231 self.assertEqual(set(subtitles.keys()), set(['en']))
232 self.assertEqual(md5(subtitles['en']), '09bbe67222259bed60deaa26997d73a7')
233
234
235 class TestNPOSubtitles(BaseTestSubtitles):
236 url = 'http://www.npo.nl/nos-journaal/28-08-2014/POW_00722860'
237 IE = NPOIE
238
239 def test_allsubtitles(self):
240 self.DL.params['writesubtitles'] = True
241 self.DL.params['allsubtitles'] = True
242 subtitles = self.getSubtitles()
243 self.assertEqual(set(subtitles.keys()), set(['nl']))
244 self.assertEqual(md5(subtitles['nl']), 'fc6435027572b63fb4ab143abd5ad3f4')
245
246
247 class TestMTVSubtitles(BaseTestSubtitles):
248 url = 'http://www.cc.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother'
249 IE = ComedyCentralIE
250
251 def getInfoDict(self):
252 return super(TestMTVSubtitles, self).getInfoDict()['entries'][0]
253
254 def test_allsubtitles(self):
255 self.DL.params['writesubtitles'] = True
256 self.DL.params['allsubtitles'] = True
257 subtitles = self.getSubtitles()
258 self.assertEqual(set(subtitles.keys()), set(['en']))
259 self.assertEqual(md5(subtitles['en']), 'b9f6ca22a6acf597ec76f61749765e65')
260
261
262 class TestNRKSubtitles(BaseTestSubtitles):
263 url = 'http://tv.nrk.no/serie/ikke-gjoer-dette-hjemme/DMPV73000411/sesong-2/episode-1'
264 IE = NRKTVIE
265
266 def test_allsubtitles(self):
267 self.DL.params['writesubtitles'] = True
268 self.DL.params['allsubtitles'] = True
269 subtitles = self.getSubtitles()
270 self.assertEqual(set(subtitles.keys()), set(['no']))
271 self.assertEqual(md5(subtitles['no']), '544fa917d3197fcbee64634559221cc2')
272
273
274 class TestRaiSubtitles(BaseTestSubtitles):
275 url = 'http://www.rai.tv/dl/RaiTV/programmi/media/ContentItem-cb27157f-9dd0-4aee-b788-b1f67643a391.html'
276 IE = RaiIE
277
278 def test_allsubtitles(self):
279 self.DL.params['writesubtitles'] = True
280 self.DL.params['allsubtitles'] = True
281 subtitles = self.getSubtitles()
282 self.assertEqual(set(subtitles.keys()), set(['it']))
283 self.assertEqual(md5(subtitles['it']), 'b1d90a98755126b61e667567a1f6680a')
284
285
286 class TestVikiSubtitles(BaseTestSubtitles):
287 url = 'http://www.viki.com/videos/1060846v-punch-episode-18'
288 IE = VikiIE
289
290 def test_allsubtitles(self):
291 self.DL.params['writesubtitles'] = True
292 self.DL.params['allsubtitles'] = True
293 subtitles = self.getSubtitles()
294 self.assertEqual(set(subtitles.keys()), set(['en']))
295 self.assertEqual(md5(subtitles['en']), '53cb083a5914b2d84ef1ab67b880d18a')
296
297
298 class TestThePlatformSubtitles(BaseTestSubtitles):
299 # from http://www.3playmedia.com/services-features/tools/integrations/theplatform/
300 # (see http://theplatform.com/about/partners/type/subtitles-closed-captioning/)
301 url = 'theplatform:JFUjUE1_ehvq'
302 IE = ThePlatformIE
303
304 def test_allsubtitles(self):
305 self.DL.params['writesubtitles'] = True
306 self.DL.params['allsubtitles'] = True
307 subtitles = self.getSubtitles()
308 self.assertEqual(set(subtitles.keys()), set(['en']))
309 self.assertEqual(md5(subtitles['en']), '97e7670cbae3c4d26ae8bcc7fdd78d4b')
310
311
312 class TestThePlatformFeedSubtitles(BaseTestSubtitles):
313 url = 'http://feed.theplatform.com/f/7wvmTC/msnbc_video-p-test?form=json&pretty=true&range=-40&byGuid=n_hardball_5biden_140207'
314 IE = ThePlatformFeedIE
315
316 def test_allsubtitles(self):
317 self.DL.params['writesubtitles'] = True
318 self.DL.params['allsubtitles'] = True
319 subtitles = self.getSubtitles()
320 self.assertEqual(set(subtitles.keys()), set(['en']))
321 self.assertEqual(md5(subtitles['en']), '48649a22e82b2da21c9a67a395eedade')
322
323
324 class TestRtveSubtitles(BaseTestSubtitles):
325 url = 'http://www.rtve.es/alacarta/videos/los-misterios-de-laura/misterios-laura-capitulo-32-misterio-del-numero-17-2-parte/2428621/'
326 IE = RTVEALaCartaIE
327
328 def test_allsubtitles(self):
329 print('Skipping, only available from Spain')
330 return
331 self.DL.params['writesubtitles'] = True
332 self.DL.params['allsubtitles'] = True
333 subtitles = self.getSubtitles()
334 self.assertEqual(set(subtitles.keys()), set(['es']))
335 self.assertEqual(md5(subtitles['es']), '69e70cae2d40574fb7316f31d6eb7fca')
336
337
338 class TestFunnyOrDieSubtitles(BaseTestSubtitles):
339 url = 'http://www.funnyordie.com/videos/224829ff6d/judd-apatow-will-direct-your-vine'
340 IE = FunnyOrDieIE
341
342 def test_allsubtitles(self):
343 self.DL.params['writesubtitles'] = True
344 self.DL.params['allsubtitles'] = True
345 subtitles = self.getSubtitles()
346 self.assertEqual(set(subtitles.keys()), set(['en']))
347 self.assertEqual(md5(subtitles['en']), 'c5593c193eacd353596c11c2d4f9ecc4')
348
349
350 class TestDemocracynowSubtitles(BaseTestSubtitles):
351 url = 'http://www.democracynow.org/shows/2015/7/3'
352 IE = DemocracynowIE
353
354 def test_allsubtitles(self):
355 self.DL.params['writesubtitles'] = True
356 self.DL.params['allsubtitles'] = True
357 subtitles = self.getSubtitles()
358 self.assertEqual(set(subtitles.keys()), set(['en']))
359 self.assertEqual(md5(subtitles['en']), 'acaca989e24a9e45a6719c9b3d60815c')
360
361 def test_subtitles_in_page(self):
362 self.url = 'http://www.democracynow.org/2015/7/3/this_flag_comes_down_today_bree'
363 self.DL.params['writesubtitles'] = True
364 self.DL.params['allsubtitles'] = True
365 subtitles = self.getSubtitles()
366 self.assertEqual(set(subtitles.keys()), set(['en']))
367 self.assertEqual(md5(subtitles['en']), 'acaca989e24a9e45a6719c9b3d60815c')
368
369
370 if __name__ == '__main__':
371 unittest.main()