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 (
33 class BaseTestSubtitles(unittest.TestCase):
40 self.DL.add_info_extractor(self.ie)
42 def getInfoDict(self):
43 info_dict = self.DL.extract_info(self.url, download=False)
46 def getSubtitles(self):
47 info_dict = self.getInfoDict()
48 subtitles = info_dict['requested_subtitles']
51 for sub_info in subtitles.values():
52 if sub_info.get('data') is None:
53 uf = self.DL.urlopen(sub_info['url'])
54 sub_info['data'] = uf.read().decode('utf-8')
55 return dict((l, sub_info['data']) for l, sub_info in subtitles.items())
58 class TestYoutubeSubtitles(BaseTestSubtitles):
62 def test_youtube_allsubtitles(self):
63 self.DL.params['writesubtitles'] = True
64 self.DL.params['allsubtitles'] = True
65 subtitles = self.getSubtitles()
66 self.assertEqual(len(subtitles.keys()), 13)
67 self.assertEqual(md5(subtitles['en']), '4cd9278a35ba2305f47354ee13472260')
68 self.assertEqual(md5(subtitles['it']), '164a51f16f260476a05b50fe4c2f161d')
69 for lang in ['it', 'fr', 'de']:
70 self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
72 def test_youtube_subtitles_sbv_format(self):
73 self.DL.params['writesubtitles'] = True
74 self.DL.params['subtitlesformat'] = 'sbv'
75 subtitles = self.getSubtitles()
76 self.assertEqual(md5(subtitles['en']), '13aeaa0c245a8bed9a451cb643e3ad8b')
78 def test_youtube_subtitles_vtt_format(self):
79 self.DL.params['writesubtitles'] = True
80 self.DL.params['subtitlesformat'] = 'vtt'
81 subtitles = self.getSubtitles()
82 self.assertEqual(md5(subtitles['en']), '3cb210999d3e021bd6c7f0ea751eab06')
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)
91 def test_youtube_translated_subtitles(self):
92 # This video has a subtitles track, which can be translated
93 self.url = 'Ky9eprVWzlI'
94 self.DL.params['writeautomaticsub'] = True
95 self.DL.params['subtitleslangs'] = ['it']
96 subtitles = self.getSubtitles()
97 self.assertTrue(subtitles['it'] is not None)
99 def test_youtube_nosubtitles(self):
100 self.DL.expect_warning('video doesn\'t have subtitles')
101 self.url = 'n5BB19UTcdA'
102 self.DL.params['writesubtitles'] = True
103 self.DL.params['allsubtitles'] = True
104 subtitles = self.getSubtitles()
105 self.assertFalse(subtitles)
108 class TestDailymotionSubtitles(BaseTestSubtitles):
109 url = 'http://www.dailymotion.com/video/xczg00'
112 def test_allsubtitles(self):
113 self.DL.params['writesubtitles'] = True
114 self.DL.params['allsubtitles'] = True
115 subtitles = self.getSubtitles()
116 self.assertTrue(len(subtitles.keys()) >= 6)
117 self.assertEqual(md5(subtitles['en']), '976553874490cba125086bbfea3ff76f')
118 self.assertEqual(md5(subtitles['fr']), '594564ec7d588942e384e920e5341792')
119 for lang in ['es', 'fr', 'de']:
120 self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
122 def test_nosubtitles(self):
123 self.DL.expect_warning('video doesn\'t have subtitles')
124 self.url = 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
125 self.DL.params['writesubtitles'] = True
126 self.DL.params['allsubtitles'] = True
127 subtitles = self.getSubtitles()
128 self.assertFalse(subtitles)
131 class TestTedSubtitles(BaseTestSubtitles):
132 url = 'http://www.ted.com/talks/dan_dennett_on_our_consciousness.html'
135 def test_allsubtitles(self):
136 self.DL.params['writesubtitles'] = True
137 self.DL.params['allsubtitles'] = True
138 subtitles = self.getSubtitles()
139 self.assertTrue(len(subtitles.keys()) >= 28)
140 self.assertEqual(md5(subtitles['en']), '4262c1665ff928a2dada178f62cb8d14')
141 self.assertEqual(md5(subtitles['fr']), '66a63f7f42c97a50f8c0e90bc7797bb5')
142 for lang in ['es', 'fr', 'de']:
143 self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
146 class TestBlipTVSubtitles(BaseTestSubtitles):
147 url = 'http://blip.tv/a/a-6603250'
150 def test_allsubtitles(self):
151 self.DL.params['writesubtitles'] = True
152 self.DL.params['allsubtitles'] = True
153 subtitles = self.getSubtitles()
154 self.assertEqual(set(subtitles.keys()), set(['en']))
155 self.assertEqual(md5(subtitles['en']), '5b75c300af65fe4476dff79478bb93e4')
158 class TestVimeoSubtitles(BaseTestSubtitles):
159 url = 'http://vimeo.com/76979871'
162 def test_allsubtitles(self):
163 self.DL.params['writesubtitles'] = True
164 self.DL.params['allsubtitles'] = True
165 subtitles = self.getSubtitles()
166 self.assertEqual(set(subtitles.keys()), set(['de', 'en', 'es', 'fr']))
167 self.assertEqual(md5(subtitles['en']), '8062383cf4dec168fc40a088aa6d5888')
168 self.assertEqual(md5(subtitles['fr']), 'b6191146a6c5d3a452244d853fde6dc8')
170 def test_nosubtitles(self):
171 self.DL.expect_warning('video doesn\'t have subtitles')
172 self.url = 'http://vimeo.com/56015672'
173 self.DL.params['writesubtitles'] = True
174 self.DL.params['allsubtitles'] = True
175 subtitles = self.getSubtitles()
176 self.assertFalse(subtitles)
179 class TestWallaSubtitles(BaseTestSubtitles):
180 url = 'http://vod.walla.co.il/movie/2705958/the-yes-men'
183 def test_allsubtitles(self):
184 self.DL.expect_warning('Automatic Captions not supported by this server')
185 self.DL.params['writesubtitles'] = True
186 self.DL.params['allsubtitles'] = True
187 subtitles = self.getSubtitles()
188 self.assertEqual(set(subtitles.keys()), set(['heb']))
189 self.assertEqual(md5(subtitles['heb']), 'e758c5d7cb982f6bef14f377ec7a3920')
191 def test_nosubtitles(self):
192 self.DL.expect_warning('video doesn\'t have subtitles')
193 self.url = 'http://vod.walla.co.il/movie/2642630/one-direction-all-for-one'
194 self.DL.params['writesubtitles'] = True
195 self.DL.params['allsubtitles'] = True
196 subtitles = self.getSubtitles()
197 self.assertFalse(subtitles)
200 class TestCeskaTelevizeSubtitles(BaseTestSubtitles):
201 url = 'http://www.ceskatelevize.cz/ivysilani/10600540290-u6-uzasny-svet-techniky'
204 def test_allsubtitles(self):
205 self.DL.expect_warning('Automatic Captions not supported by this server')
206 self.DL.params['writesubtitles'] = True
207 self.DL.params['allsubtitles'] = True
208 subtitles = self.getSubtitles()
209 self.assertEqual(set(subtitles.keys()), set(['cs']))
210 self.assertTrue(len(subtitles['cs']) > 20000)
212 def test_nosubtitles(self):
213 self.DL.expect_warning('video doesn\'t have subtitles')
214 self.url = 'http://www.ceskatelevize.cz/ivysilani/ivysilani/10441294653-hyde-park-civilizace/214411058091220'
215 self.DL.params['writesubtitles'] = True
216 self.DL.params['allsubtitles'] = True
217 subtitles = self.getSubtitles()
218 self.assertFalse(subtitles)
221 class TestLyndaSubtitles(BaseTestSubtitles):
222 url = 'http://www.lynda.com/Bootstrap-tutorials/Using-exercise-files/110885/114408-4.html'
225 def test_allsubtitles(self):
226 self.DL.params['writesubtitles'] = True
227 self.DL.params['allsubtitles'] = True
228 subtitles = self.getSubtitles()
229 self.assertEqual(set(subtitles.keys()), set(['en']))
230 self.assertEqual(md5(subtitles['en']), '09bbe67222259bed60deaa26997d73a7')
233 class TestNPOSubtitles(BaseTestSubtitles):
234 url = 'http://www.npo.nl/nos-journaal/28-08-2014/POW_00722860'
237 def test_allsubtitles(self):
238 self.DL.params['writesubtitles'] = True
239 self.DL.params['allsubtitles'] = True
240 subtitles = self.getSubtitles()
241 self.assertEqual(set(subtitles.keys()), set(['nl']))
242 self.assertEqual(md5(subtitles['nl']), 'fc6435027572b63fb4ab143abd5ad3f4')
245 class TestMTVSubtitles(BaseTestSubtitles):
246 url = 'http://www.cc.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother'
249 def getInfoDict(self):
250 return super(TestMTVSubtitles, self).getInfoDict()['entries'][0]
252 def test_allsubtitles(self):
253 self.DL.params['writesubtitles'] = True
254 self.DL.params['allsubtitles'] = True
255 subtitles = self.getSubtitles()
256 self.assertEqual(set(subtitles.keys()), set(['en']))
257 self.assertEqual(md5(subtitles['en']), 'b9f6ca22a6acf597ec76f61749765e65')
260 class TestNRKSubtitles(BaseTestSubtitles):
261 url = 'http://tv.nrk.no/serie/ikke-gjoer-dette-hjemme/DMPV73000411/sesong-2/episode-1'
264 def test_allsubtitles(self):
265 self.DL.params['writesubtitles'] = True
266 self.DL.params['allsubtitles'] = True
267 subtitles = self.getSubtitles()
268 self.assertEqual(set(subtitles.keys()), set(['no']))
269 self.assertEqual(md5(subtitles['no']), '544fa917d3197fcbee64634559221cc2')
272 class TestRaiSubtitles(BaseTestSubtitles):
273 url = 'http://www.rai.tv/dl/RaiTV/programmi/media/ContentItem-cb27157f-9dd0-4aee-b788-b1f67643a391.html'
276 def test_allsubtitles(self):
277 self.DL.params['writesubtitles'] = True
278 self.DL.params['allsubtitles'] = True
279 subtitles = self.getSubtitles()
280 self.assertEqual(set(subtitles.keys()), set(['it']))
281 self.assertEqual(md5(subtitles['it']), 'b1d90a98755126b61e667567a1f6680a')
284 class TestVikiSubtitles(BaseTestSubtitles):
285 url = 'http://www.viki.com/videos/1060846v-punch-episode-18'
288 def test_allsubtitles(self):
289 self.DL.params['writesubtitles'] = True
290 self.DL.params['allsubtitles'] = True
291 subtitles = self.getSubtitles()
292 self.assertEqual(set(subtitles.keys()), set(['en']))
293 self.assertEqual(md5(subtitles['en']), '53cb083a5914b2d84ef1ab67b880d18a')
296 class TestThePlatformSubtitles(BaseTestSubtitles):
297 # from http://www.3playmedia.com/services-features/tools/integrations/theplatform/
298 # (see http://theplatform.com/about/partners/type/subtitles-closed-captioning/)
299 url = 'theplatform:JFUjUE1_ehvq'
302 def test_allsubtitles(self):
303 self.DL.params['writesubtitles'] = True
304 self.DL.params['allsubtitles'] = True
305 subtitles = self.getSubtitles()
306 self.assertEqual(set(subtitles.keys()), set(['en']))
307 self.assertEqual(md5(subtitles['en']), '97e7670cbae3c4d26ae8bcc7fdd78d4b')
310 class TestRtveSubtitles(BaseTestSubtitles):
311 url = 'http://www.rtve.es/alacarta/videos/los-misterios-de-laura/misterios-laura-capitulo-32-misterio-del-numero-17-2-parte/2428621/'
314 def test_allsubtitles(self):
315 print('Skipping, only available from Spain')
317 self.DL.params['writesubtitles'] = True
318 self.DL.params['allsubtitles'] = True
319 subtitles = self.getSubtitles()
320 self.assertEqual(set(subtitles.keys()), set(['es']))
321 self.assertEqual(md5(subtitles['es']), '69e70cae2d40574fb7316f31d6eb7fca')
324 class TestFunnyOrDieSubtitles(BaseTestSubtitles):
325 url = 'http://www.funnyordie.com/videos/224829ff6d/judd-apatow-will-direct-your-vine'
328 def test_allsubtitles(self):
329 self.DL.params['writesubtitles'] = True
330 self.DL.params['allsubtitles'] = True
331 subtitles = self.getSubtitles()
332 self.assertEqual(set(subtitles.keys()), set(['en']))
333 self.assertEqual(md5(subtitles['en']), 'c5593c193eacd353596c11c2d4f9ecc4')
336 if __name__ == '__main__':