]>
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 (
32 class BaseTestSubtitles(unittest
.TestCase
):
39 self
.DL
.add_info_extractor(self
.ie
)
41 def getInfoDict(self
):
42 info_dict
= self
.DL
.extract_info(self
.url
, download
=False)
45 def getSubtitles(self
):
46 info_dict
= self
.getInfoDict()
47 subtitles
= info_dict
['requested_subtitles']
50 for sub_info
in subtitles
.values():
51 if sub_info
.get('data') is None:
52 uf
= self
.DL
.urlopen(sub_info
['url'])
53 sub_info
['data'] = uf
.read().decode('utf-8')
54 return dict((l
, sub_info
['data']) for l
, sub_info
in subtitles
.items())
57 class TestYoutubeSubtitles(BaseTestSubtitles
):
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)
66 self
.assertEqual(md5(subtitles
['en']), '4cd9278a35ba2305f47354ee13472260')
67 self
.assertEqual(md5(subtitles
['it']), '164a51f16f260476a05b50fe4c2f161d')
68 for lang
in ['it', 'fr', 'de']:
69 self
.assertTrue(subtitles
.get(lang
) is not None, 'Subtitles for \'%s\' not extracted' % lang
)
71 def test_youtube_subtitles_sbv_format(self
):
72 self
.DL
.params
['writesubtitles'] = True
73 self
.DL
.params
['subtitlesformat'] = 'sbv'
74 subtitles
= self
.getSubtitles()
75 self
.assertEqual(md5(subtitles
['en']), '13aeaa0c245a8bed9a451cb643e3ad8b')
77 def test_youtube_subtitles_vtt_format(self
):
78 self
.DL
.params
['writesubtitles'] = True
79 self
.DL
.params
['subtitlesformat'] = 'vtt'
80 subtitles
= self
.getSubtitles()
81 self
.assertEqual(md5(subtitles
['en']), '3cb210999d3e021bd6c7f0ea751eab06')
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_translated_subtitles(self
):
91 # This video has a subtitles track, which can be translated
92 self
.url
= 'Ky9eprVWzlI'
93 self
.DL
.params
['writeautomaticsub'] = True
94 self
.DL
.params
['subtitleslangs'] = ['it']
95 subtitles
= self
.getSubtitles()
96 self
.assertTrue(subtitles
['it'] is not None)
98 def test_youtube_nosubtitles(self
):
99 self
.DL
.expect_warning('video doesn\'t have subtitles')
100 self
.url
= 'n5BB19UTcdA'
101 self
.DL
.params
['writesubtitles'] = True
102 self
.DL
.params
['allsubtitles'] = True
103 subtitles
= self
.getSubtitles()
104 self
.assertFalse(subtitles
)
107 class TestDailymotionSubtitles(BaseTestSubtitles
):
108 url
= 'http://www.dailymotion.com/video/xczg00'
111 def test_allsubtitles(self
):
112 self
.DL
.params
['writesubtitles'] = True
113 self
.DL
.params
['allsubtitles'] = True
114 subtitles
= self
.getSubtitles()
115 self
.assertTrue(len(subtitles
.keys()) >= 6)
116 self
.assertEqual(md5(subtitles
['en']), '976553874490cba125086bbfea3ff76f')
117 self
.assertEqual(md5(subtitles
['fr']), '594564ec7d588942e384e920e5341792')
118 for lang
in ['es', 'fr', 'de']:
119 self
.assertTrue(subtitles
.get(lang
) is not None, 'Subtitles for \'%s\' not extracted' % lang
)
121 def test_nosubtitles(self
):
122 self
.DL
.expect_warning('video doesn\'t have subtitles')
123 self
.url
= 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
124 self
.DL
.params
['writesubtitles'] = True
125 self
.DL
.params
['allsubtitles'] = True
126 subtitles
= self
.getSubtitles()
127 self
.assertFalse(subtitles
)
130 class TestTedSubtitles(BaseTestSubtitles
):
131 url
= 'http://www.ted.com/talks/dan_dennett_on_our_consciousness.html'
134 def test_allsubtitles(self
):
135 self
.DL
.params
['writesubtitles'] = True
136 self
.DL
.params
['allsubtitles'] = True
137 subtitles
= self
.getSubtitles()
138 self
.assertTrue(len(subtitles
.keys()) >= 28)
139 self
.assertEqual(md5(subtitles
['en']), '4262c1665ff928a2dada178f62cb8d14')
140 self
.assertEqual(md5(subtitles
['fr']), '66a63f7f42c97a50f8c0e90bc7797bb5')
141 for lang
in ['es', 'fr', 'de']:
142 self
.assertTrue(subtitles
.get(lang
) is not None, 'Subtitles for \'%s\' not extracted' % lang
)
145 class TestBlipTVSubtitles(BaseTestSubtitles
):
146 url
= 'http://blip.tv/a/a-6603250'
149 def test_allsubtitles(self
):
150 self
.DL
.params
['writesubtitles'] = True
151 self
.DL
.params
['allsubtitles'] = True
152 subtitles
= self
.getSubtitles()
153 self
.assertEqual(set(subtitles
.keys()), set(['en']))
154 self
.assertEqual(md5(subtitles
['en']), '5b75c300af65fe4476dff79478bb93e4')
157 class TestVimeoSubtitles(BaseTestSubtitles
):
158 url
= 'http://vimeo.com/76979871'
161 def test_allsubtitles(self
):
162 self
.DL
.params
['writesubtitles'] = True
163 self
.DL
.params
['allsubtitles'] = True
164 subtitles
= self
.getSubtitles()
165 self
.assertEqual(set(subtitles
.keys()), set(['de', 'en', 'es', 'fr']))
166 self
.assertEqual(md5(subtitles
['en']), '8062383cf4dec168fc40a088aa6d5888')
167 self
.assertEqual(md5(subtitles
['fr']), 'b6191146a6c5d3a452244d853fde6dc8')
169 def test_nosubtitles(self
):
170 self
.DL
.expect_warning('video doesn\'t have subtitles')
171 self
.url
= 'http://vimeo.com/56015672'
172 self
.DL
.params
['writesubtitles'] = True
173 self
.DL
.params
['allsubtitles'] = True
174 subtitles
= self
.getSubtitles()
175 self
.assertFalse(subtitles
)
178 class TestWallaSubtitles(BaseTestSubtitles
):
179 url
= 'http://vod.walla.co.il/movie/2705958/the-yes-men'
182 def test_allsubtitles(self
):
183 self
.DL
.expect_warning('Automatic Captions not supported by this server')
184 self
.DL
.params
['writesubtitles'] = True
185 self
.DL
.params
['allsubtitles'] = True
186 subtitles
= self
.getSubtitles()
187 self
.assertEqual(set(subtitles
.keys()), set(['heb']))
188 self
.assertEqual(md5(subtitles
['heb']), 'e758c5d7cb982f6bef14f377ec7a3920')
190 def test_nosubtitles(self
):
191 self
.DL
.expect_warning('video doesn\'t have subtitles')
192 self
.url
= 'http://vod.walla.co.il/movie/2642630/one-direction-all-for-one'
193 self
.DL
.params
['writesubtitles'] = True
194 self
.DL
.params
['allsubtitles'] = True
195 subtitles
= self
.getSubtitles()
196 self
.assertFalse(subtitles
)
199 class TestCeskaTelevizeSubtitles(BaseTestSubtitles
):
200 url
= 'http://www.ceskatelevize.cz/ivysilani/10600540290-u6-uzasny-svet-techniky'
203 def test_allsubtitles(self
):
204 self
.DL
.expect_warning('Automatic Captions not supported by this server')
205 self
.DL
.params
['writesubtitles'] = True
206 self
.DL
.params
['allsubtitles'] = True
207 subtitles
= self
.getSubtitles()
208 self
.assertEqual(set(subtitles
.keys()), set(['cs']))
209 self
.assertTrue(len(subtitles
['cs']) > 20000)
211 def test_nosubtitles(self
):
212 self
.DL
.expect_warning('video doesn\'t have subtitles')
213 self
.url
= 'http://www.ceskatelevize.cz/ivysilani/ivysilani/10441294653-hyde-park-civilizace/214411058091220'
214 self
.DL
.params
['writesubtitles'] = True
215 self
.DL
.params
['allsubtitles'] = True
216 subtitles
= self
.getSubtitles()
217 self
.assertFalse(subtitles
)
220 class TestLyndaSubtitles(BaseTestSubtitles
):
221 url
= 'http://www.lynda.com/Bootstrap-tutorials/Using-exercise-files/110885/114408-4.html'
224 def test_allsubtitles(self
):
225 self
.DL
.params
['writesubtitles'] = True
226 self
.DL
.params
['allsubtitles'] = True
227 subtitles
= self
.getSubtitles()
228 self
.assertEqual(set(subtitles
.keys()), set(['en']))
229 self
.assertEqual(md5(subtitles
['en']), '09bbe67222259bed60deaa26997d73a7')
232 class TestNPOSubtitles(BaseTestSubtitles
):
233 url
= 'http://www.npo.nl/nos-journaal/28-08-2014/POW_00722860'
236 def test_allsubtitles(self
):
237 self
.DL
.params
['writesubtitles'] = True
238 self
.DL
.params
['allsubtitles'] = True
239 subtitles
= self
.getSubtitles()
240 self
.assertEqual(set(subtitles
.keys()), set(['nl']))
241 self
.assertEqual(md5(subtitles
['nl']), 'fc6435027572b63fb4ab143abd5ad3f4')
244 class TestMTVSubtitles(BaseTestSubtitles
):
245 url
= 'http://www.cc.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother'
248 def getInfoDict(self
):
249 return super(TestMTVSubtitles
, self
).getInfoDict()['entries'][0]
251 def test_allsubtitles(self
):
252 self
.DL
.params
['writesubtitles'] = True
253 self
.DL
.params
['allsubtitles'] = True
254 subtitles
= self
.getSubtitles()
255 self
.assertEqual(set(subtitles
.keys()), set(['en']))
256 self
.assertEqual(md5(subtitles
['en']), 'b9f6ca22a6acf597ec76f61749765e65')
259 class TestNRKSubtitles(BaseTestSubtitles
):
260 url
= 'http://tv.nrk.no/serie/ikke-gjoer-dette-hjemme/DMPV73000411/sesong-2/episode-1'
263 def test_allsubtitles(self
):
264 self
.DL
.params
['writesubtitles'] = True
265 self
.DL
.params
['allsubtitles'] = True
266 subtitles
= self
.getSubtitles()
267 self
.assertEqual(set(subtitles
.keys()), set(['no']))
268 self
.assertEqual(md5(subtitles
['no']), '1d221e6458c95c5494dcd38e6a1f129a')
271 class TestRaiSubtitles(BaseTestSubtitles
):
272 url
= 'http://www.rai.tv/dl/RaiTV/programmi/media/ContentItem-cb27157f-9dd0-4aee-b788-b1f67643a391.html'
275 def test_allsubtitles(self
):
276 self
.DL
.params
['writesubtitles'] = True
277 self
.DL
.params
['allsubtitles'] = True
278 subtitles
= self
.getSubtitles()
279 self
.assertEqual(set(subtitles
.keys()), set(['it']))
280 self
.assertEqual(md5(subtitles
['it']), 'b1d90a98755126b61e667567a1f6680a')
283 class TestVikiSubtitles(BaseTestSubtitles
):
284 url
= 'http://www.viki.com/videos/1060846v-punch-episode-18'
287 def test_allsubtitles(self
):
288 self
.DL
.params
['writesubtitles'] = True
289 self
.DL
.params
['allsubtitles'] = True
290 subtitles
= self
.getSubtitles()
291 self
.assertEqual(set(subtitles
.keys()), set(['en']))
292 self
.assertEqual(md5(subtitles
['en']), '53cb083a5914b2d84ef1ab67b880d18a')
295 class TestThePlatformSubtitles(BaseTestSubtitles
):
296 # from http://www.3playmedia.com/services-features/tools/integrations/theplatform/
297 # (see http://theplatform.com/about/partners/type/subtitles-closed-captioning/)
298 url
= 'theplatform:JFUjUE1_ehvq'
301 def test_allsubtitles(self
):
302 self
.DL
.params
['writesubtitles'] = True
303 self
.DL
.params
['allsubtitles'] = True
304 subtitles
= self
.getSubtitles()
305 self
.assertEqual(set(subtitles
.keys()), set(['en']))
306 self
.assertEqual(md5(subtitles
['en']), '97e7670cbae3c4d26ae8bcc7fdd78d4b')
309 class TestRtveSubtitles(BaseTestSubtitles
):
310 url
= 'http://www.rtve.es/alacarta/videos/los-misterios-de-laura/misterios-laura-capitulo-32-misterio-del-numero-17-2-parte/2428621/'
313 def test_allsubtitles(self
):
314 print('Skipping, only available from Spain')
316 self
.DL
.params
['writesubtitles'] = True
317 self
.DL
.params
['allsubtitles'] = True
318 subtitles
= self
.getSubtitles()
319 self
.assertEqual(set(subtitles
.keys()), set(['es']))
320 self
.assertEqual(md5(subtitles
['es']), '69e70cae2d40574fb7316f31d6eb7fca')
323 if __name__
== '__main__':