]>
Commit | Line | Data |
---|---|---|
ae84f879 | 1 | #!/usr/bin/env python |
a0f59cdc | 2 | from __future__ import unicode_literals |
ae84f879 JMF |
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 | ||
d0efb9ec | 10 | from test.helper import FakeYDL, md5 |
ae84f879 JMF |
11 | |
12 | ||
13 | from youtube_dl.extractor import ( | |
b4bcffef | 14 | BlipTVIE, |
ae84f879 JMF |
15 | YoutubeIE, |
16 | DailymotionIE, | |
17 | TEDIE, | |
4edff4cf | 18 | VimeoIE, |
7bc8780c | 19 | WallaIE, |
0b54a5b1 | 20 | CeskaTelevizeIE, |
311c3938 | 21 | LyndaIE, |
b9b42f2e | 22 | NPOIE, |
0af25f78 | 23 | ComedyCentralIE, |
01561da1 | 24 | NRKTVIE, |
afbdd3ac | 25 | RaiIE, |
4f7cea6c | 26 | VikiIE, |
8807f127 | 27 | ThePlatformIE, |
f908b74f | 28 | ThePlatformFeedIE, |
25ac63ed | 29 | RTVEALaCartaIE, |
7e195d0e | 30 | FunnyOrDieIE, |
66d041f2 | 31 | DemocracynowIE, |
ae84f879 JMF |
32 | ) |
33 | ||
34 | ||
35 | class BaseTestSubtitles(unittest.TestCase): | |
36 | url = None | |
37 | IE = None | |
5f6a1245 | 38 | |
ae84f879 JMF |
39 | def setUp(self): |
40 | self.DL = FakeYDL() | |
a504ced0 JMF |
41 | self.ie = self.IE() |
42 | self.DL.add_info_extractor(self.ie) | |
ae84f879 JMF |
43 | |
44 | def getInfoDict(self): | |
a504ced0 | 45 | info_dict = self.DL.extract_info(self.url, download=False) |
ae84f879 JMF |
46 | return info_dict |
47 | ||
48 | def getSubtitles(self): | |
49 | info_dict = self.getInfoDict() | |
c84dd8a9 | 50 | subtitles = info_dict['requested_subtitles'] |
a504ced0 JMF |
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()) | |
ae84f879 JMF |
58 | |
59 | ||
60 | class TestYoutubeSubtitles(BaseTestSubtitles): | |
61 | url = 'QRS8MkLhQmM' | |
62 | IE = YoutubeIE | |
63 | ||
ae84f879 JMF |
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) | |
b7bb76df JMF |
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) | |
ae84f879 JMF |
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() | |
4e0084d9 | 84 | self.assertEqual(md5(subtitles['en']), '3cb210999d3e021bd6c7f0ea751eab06') |
ae84f879 | 85 | |
ae84f879 JMF |
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 | ||
7d900ef1 JMF |
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 | ||
ae84f879 | 101 | def test_youtube_nosubtitles(self): |
a0f59cdc | 102 | self.DL.expect_warning('video doesn\'t have subtitles') |
345e3783 | 103 | self.url = 'n5BB19UTcdA' |
ae84f879 JMF |
104 | self.DL.params['writesubtitles'] = True |
105 | self.DL.params['allsubtitles'] = True | |
106 | subtitles = self.getSubtitles() | |
4d171848 | 107 | self.assertFalse(subtitles) |
ae84f879 | 108 | |
ae84f879 JMF |
109 | |
110 | class TestDailymotionSubtitles(BaseTestSubtitles): | |
111 | url = 'http://www.dailymotion.com/video/xczg00' | |
112 | IE = DailymotionIE | |
113 | ||
ae84f879 JMF |
114 | def test_allsubtitles(self): |
115 | self.DL.params['writesubtitles'] = True | |
116 | self.DL.params['allsubtitles'] = True | |
117 | subtitles = self.getSubtitles() | |
8fb474fb | 118 | self.assertTrue(len(subtitles.keys()) >= 6) |
b7bb76df JMF |
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) | |
ae84f879 | 123 | |
ae84f879 | 124 | def test_nosubtitles(self): |
a0f59cdc | 125 | self.DL.expect_warning('video doesn\'t have subtitles') |
ae84f879 JMF |
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() | |
4d171848 | 130 | self.assertFalse(subtitles) |
ae84f879 | 131 | |
ae84f879 JMF |
132 | |
133 | class TestTedSubtitles(BaseTestSubtitles): | |
134 | url = 'http://www.ted.com/talks/dan_dennett_on_our_consciousness.html' | |
135 | IE = TEDIE | |
136 | ||
ae84f879 JMF |
137 | def test_allsubtitles(self): |
138 | self.DL.params['writesubtitles'] = True | |
139 | self.DL.params['allsubtitles'] = True | |
140 | subtitles = self.getSubtitles() | |
0321213c | 141 | self.assertTrue(len(subtitles.keys()) >= 28) |
b7bb76df JMF |
142 | self.assertEqual(md5(subtitles['en']), '4262c1665ff928a2dada178f62cb8d14') |
143 | self.assertEqual(md5(subtitles['fr']), '66a63f7f42c97a50f8c0e90bc7797bb5') | |
144 | for lang in ['es', 'fr', 'de']: | |
a0f59cdc | 145 | self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang) |
ae84f879 | 146 | |
b4bcffef PH |
147 | |
148 | class TestBlipTVSubtitles(BaseTestSubtitles): | |
149 | url = 'http://blip.tv/a/a-6603250' | |
150 | IE = BlipTVIE | |
151 | ||
b4bcffef | 152 | def test_allsubtitles(self): |
b4bcffef PH |
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 | ||
4edff4cf S |
160 | class TestVimeoSubtitles(BaseTestSubtitles): |
161 | url = 'http://vimeo.com/76979871' | |
162 | IE = VimeoIE | |
b0268cb6 | 163 | |
4edff4cf S |
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'])) | |
b7bb76df JMF |
169 | self.assertEqual(md5(subtitles['en']), '8062383cf4dec168fc40a088aa6d5888') |
170 | self.assertEqual(md5(subtitles['fr']), 'b6191146a6c5d3a452244d853fde6dc8') | |
4edff4cf | 171 | |
4edff4cf | 172 | def test_nosubtitles(self): |
a0f59cdc | 173 | self.DL.expect_warning('video doesn\'t have subtitles') |
4edff4cf S |
174 | self.url = 'http://vimeo.com/56015672' |
175 | self.DL.params['writesubtitles'] = True | |
176 | self.DL.params['allsubtitles'] = True | |
177 | subtitles = self.getSubtitles() | |
4d171848 | 178 | self.assertFalse(subtitles) |
4edff4cf | 179 | |
4edff4cf | 180 | |
0ca41c3d | 181 | class TestWallaSubtitles(BaseTestSubtitles): |
7bc8780c S |
182 | url = 'http://vod.walla.co.il/movie/2705958/the-yes-men' |
183 | IE = WallaIE | |
184 | ||
7bc8780c | 185 | def test_allsubtitles(self): |
a0f59cdc | 186 | self.DL.expect_warning('Automatic Captions not supported by this server') |
7bc8780c S |
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): | |
a0f59cdc | 194 | self.DL.expect_warning('video doesn\'t have subtitles') |
7bc8780c S |
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() | |
4d171848 | 199 | self.assertFalse(subtitles) |
7bc8780c S |
200 | |
201 | ||
0b54a5b1 S |
202 | class TestCeskaTelevizeSubtitles(BaseTestSubtitles): |
203 | url = 'http://www.ceskatelevize.cz/ivysilani/10600540290-u6-uzasny-svet-techniky' | |
204 | IE = CeskaTelevizeIE | |
205 | ||
0b54a5b1 S |
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'])) | |
8fb474fb | 212 | self.assertTrue(len(subtitles['cs']) > 20000) |
0b54a5b1 S |
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() | |
4d171848 | 220 | self.assertFalse(subtitles) |
0b54a5b1 S |
221 | |
222 | ||
311c3938 JMF |
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 | ||
b9b42f2e JMF |
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 | ||
0af25f78 JMF |
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 | ||
01561da1 JMF |
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'])) | |
f0bfaa2d | 271 | self.assertEqual(md5(subtitles['no']), '544fa917d3197fcbee64634559221cc2') |
01561da1 JMF |
272 | |
273 | ||
afbdd3ac JMF |
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 | ||
4f7cea6c JMF |
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'])) | |
80970e53 | 295 | self.assertEqual(md5(subtitles['en']), '53cb083a5914b2d84ef1ab67b880d18a') |
4f7cea6c JMF |
296 | |
297 | ||
8807f127 JMF |
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 | ||
f908b74f YCH |
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 | ||
25ac63ed JMF |
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 | ||
7e195d0e S |
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 | ||
66d041f2 YCH |
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 | ||
ae84f879 JMF |
370 | if __name__ == '__main__': |
371 | unittest.main() |