]>
Commit | Line | Data |
---|---|---|
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_dlc.extractor import ( | |
14 | YoutubeIE, | |
15 | DailymotionIE, | |
16 | TEDIE, | |
17 | VimeoIE, | |
18 | WallaIE, | |
19 | CeskaTelevizeIE, | |
20 | LyndaIE, | |
21 | NPOIE, | |
22 | ComedyCentralIE, | |
23 | NRKTVIE, | |
24 | RaiPlayIE, | |
25 | VikiIE, | |
26 | ThePlatformIE, | |
27 | ThePlatformFeedIE, | |
28 | RTVEALaCartaIE, | |
29 | DemocracynowIE, | |
30 | ) | |
31 | ||
32 | ||
33 | class BaseTestSubtitles(unittest.TestCase): | |
34 | url = None | |
35 | IE = None | |
36 | ||
37 | def setUp(self): | |
38 | self.DL = FakeYDL() | |
39 | self.ie = self.IE() | |
40 | self.DL.add_info_extractor(self.ie) | |
41 | ||
42 | def getInfoDict(self): | |
43 | info_dict = self.DL.extract_info(self.url, download=False) | |
44 | return info_dict | |
45 | ||
46 | def getSubtitles(self): | |
47 | info_dict = self.getInfoDict() | |
48 | subtitles = info_dict['requested_subtitles'] | |
49 | if not subtitles: | |
50 | return 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()) | |
56 | ||
57 | ||
58 | class TestYoutubeSubtitles(BaseTestSubtitles): | |
59 | url = 'QRS8MkLhQmM' | |
60 | IE = YoutubeIE | |
61 | ||
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']), '688dd1ce0981683867e7fe6fde2a224b') | |
68 | self.assertEqual(md5(subtitles['it']), '31324d30b8430b309f7f5979a504a769') | |
69 | for lang in ['fr', 'de']: | |
70 | self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang) | |
71 | ||
72 | def test_youtube_subtitles_ttml_format(self): | |
73 | self.DL.params['writesubtitles'] = True | |
74 | self.DL.params['subtitlesformat'] = 'ttml' | |
75 | subtitles = self.getSubtitles() | |
76 | self.assertEqual(md5(subtitles['en']), 'c97ddf1217390906fa9fbd34901f3da2') | |
77 | ||
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']), 'ae1bd34126571a77aabd4d276b28044d') | |
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_no_automatic_captions(self): | |
92 | self.url = 'QRS8MkLhQmM' | |
93 | self.DL.params['writeautomaticsub'] = True | |
94 | subtitles = self.getSubtitles() | |
95 | self.assertTrue(not subtitles) | |
96 | ||
97 | def test_youtube_translated_subtitles(self): | |
98 | # This video has a subtitles track, which can be translated | |
99 | self.url = 'i0ZabxXmH4Y' | |
100 | self.DL.params['writeautomaticsub'] = True | |
101 | self.DL.params['subtitleslangs'] = ['it'] | |
102 | subtitles = self.getSubtitles() | |
103 | self.assertTrue(subtitles['it'] is not None) | |
104 | ||
105 | def test_youtube_nosubtitles(self): | |
106 | self.DL.expect_warning('video doesn\'t have subtitles') | |
107 | self.url = 'n5BB19UTcdA' | |
108 | self.DL.params['writesubtitles'] = True | |
109 | self.DL.params['allsubtitles'] = True | |
110 | subtitles = self.getSubtitles() | |
111 | self.assertFalse(subtitles) | |
112 | ||
113 | ||
114 | class TestDailymotionSubtitles(BaseTestSubtitles): | |
115 | url = 'http://www.dailymotion.com/video/xczg00' | |
116 | IE = DailymotionIE | |
117 | ||
118 | def test_allsubtitles(self): | |
119 | self.DL.params['writesubtitles'] = True | |
120 | self.DL.params['allsubtitles'] = True | |
121 | subtitles = self.getSubtitles() | |
122 | self.assertTrue(len(subtitles.keys()) >= 6) | |
123 | self.assertEqual(md5(subtitles['en']), '976553874490cba125086bbfea3ff76f') | |
124 | self.assertEqual(md5(subtitles['fr']), '594564ec7d588942e384e920e5341792') | |
125 | for lang in ['es', 'fr', 'de']: | |
126 | self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang) | |
127 | ||
128 | def test_nosubtitles(self): | |
129 | self.DL.expect_warning('video doesn\'t have subtitles') | |
130 | self.url = 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv' | |
131 | self.DL.params['writesubtitles'] = True | |
132 | self.DL.params['allsubtitles'] = True | |
133 | subtitles = self.getSubtitles() | |
134 | self.assertFalse(subtitles) | |
135 | ||
136 | ||
137 | class TestTedSubtitles(BaseTestSubtitles): | |
138 | url = 'http://www.ted.com/talks/dan_dennett_on_our_consciousness.html' | |
139 | IE = TEDIE | |
140 | ||
141 | def test_allsubtitles(self): | |
142 | self.DL.params['writesubtitles'] = True | |
143 | self.DL.params['allsubtitles'] = True | |
144 | subtitles = self.getSubtitles() | |
145 | self.assertTrue(len(subtitles.keys()) >= 28) | |
146 | self.assertEqual(md5(subtitles['en']), '4262c1665ff928a2dada178f62cb8d14') | |
147 | self.assertEqual(md5(subtitles['fr']), '66a63f7f42c97a50f8c0e90bc7797bb5') | |
148 | for lang in ['es', 'fr', 'de']: | |
149 | self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang) | |
150 | ||
151 | ||
152 | class TestVimeoSubtitles(BaseTestSubtitles): | |
153 | url = 'http://vimeo.com/76979871' | |
154 | IE = VimeoIE | |
155 | ||
156 | def test_allsubtitles(self): | |
157 | self.DL.params['writesubtitles'] = True | |
158 | self.DL.params['allsubtitles'] = True | |
159 | subtitles = self.getSubtitles() | |
160 | self.assertEqual(set(subtitles.keys()), set(['de', 'en', 'es', 'fr'])) | |
161 | self.assertEqual(md5(subtitles['en']), '8062383cf4dec168fc40a088aa6d5888') | |
162 | self.assertEqual(md5(subtitles['fr']), 'b6191146a6c5d3a452244d853fde6dc8') | |
163 | ||
164 | def test_nosubtitles(self): | |
165 | self.DL.expect_warning('video doesn\'t have subtitles') | |
166 | self.url = 'http://vimeo.com/56015672' | |
167 | self.DL.params['writesubtitles'] = True | |
168 | self.DL.params['allsubtitles'] = True | |
169 | subtitles = self.getSubtitles() | |
170 | self.assertFalse(subtitles) | |
171 | ||
172 | ||
173 | class TestWallaSubtitles(BaseTestSubtitles): | |
174 | url = 'http://vod.walla.co.il/movie/2705958/the-yes-men' | |
175 | IE = WallaIE | |
176 | ||
177 | def test_allsubtitles(self): | |
178 | self.DL.expect_warning('Automatic Captions not supported by this server') | |
179 | self.DL.params['writesubtitles'] = True | |
180 | self.DL.params['allsubtitles'] = True | |
181 | subtitles = self.getSubtitles() | |
182 | self.assertEqual(set(subtitles.keys()), set(['heb'])) | |
183 | self.assertEqual(md5(subtitles['heb']), 'e758c5d7cb982f6bef14f377ec7a3920') | |
184 | ||
185 | def test_nosubtitles(self): | |
186 | self.DL.expect_warning('video doesn\'t have subtitles') | |
187 | self.url = 'http://vod.walla.co.il/movie/2642630/one-direction-all-for-one' | |
188 | self.DL.params['writesubtitles'] = True | |
189 | self.DL.params['allsubtitles'] = True | |
190 | subtitles = self.getSubtitles() | |
191 | self.assertFalse(subtitles) | |
192 | ||
193 | ||
194 | class TestCeskaTelevizeSubtitles(BaseTestSubtitles): | |
195 | url = 'http://www.ceskatelevize.cz/ivysilani/10600540290-u6-uzasny-svet-techniky' | |
196 | IE = CeskaTelevizeIE | |
197 | ||
198 | def test_allsubtitles(self): | |
199 | self.DL.expect_warning('Automatic Captions not supported by this server') | |
200 | self.DL.params['writesubtitles'] = True | |
201 | self.DL.params['allsubtitles'] = True | |
202 | subtitles = self.getSubtitles() | |
203 | self.assertEqual(set(subtitles.keys()), set(['cs'])) | |
204 | self.assertTrue(len(subtitles['cs']) > 20000) | |
205 | ||
206 | def test_nosubtitles(self): | |
207 | self.DL.expect_warning('video doesn\'t have subtitles') | |
208 | self.url = 'http://www.ceskatelevize.cz/ivysilani/ivysilani/10441294653-hyde-park-civilizace/214411058091220' | |
209 | self.DL.params['writesubtitles'] = True | |
210 | self.DL.params['allsubtitles'] = True | |
211 | subtitles = self.getSubtitles() | |
212 | self.assertFalse(subtitles) | |
213 | ||
214 | ||
215 | class TestLyndaSubtitles(BaseTestSubtitles): | |
216 | url = 'http://www.lynda.com/Bootstrap-tutorials/Using-exercise-files/110885/114408-4.html' | |
217 | IE = LyndaIE | |
218 | ||
219 | def test_allsubtitles(self): | |
220 | self.DL.params['writesubtitles'] = True | |
221 | self.DL.params['allsubtitles'] = True | |
222 | subtitles = self.getSubtitles() | |
223 | self.assertEqual(set(subtitles.keys()), set(['en'])) | |
224 | self.assertEqual(md5(subtitles['en']), '09bbe67222259bed60deaa26997d73a7') | |
225 | ||
226 | ||
227 | class TestNPOSubtitles(BaseTestSubtitles): | |
228 | url = 'http://www.npo.nl/nos-journaal/28-08-2014/POW_00722860' | |
229 | IE = NPOIE | |
230 | ||
231 | def test_allsubtitles(self): | |
232 | self.DL.params['writesubtitles'] = True | |
233 | self.DL.params['allsubtitles'] = True | |
234 | subtitles = self.getSubtitles() | |
235 | self.assertEqual(set(subtitles.keys()), set(['nl'])) | |
236 | self.assertEqual(md5(subtitles['nl']), 'fc6435027572b63fb4ab143abd5ad3f4') | |
237 | ||
238 | ||
239 | class TestMTVSubtitles(BaseTestSubtitles): | |
240 | url = 'http://www.cc.com/video-clips/p63lk0/adam-devine-s-house-party-chasing-white-swans' | |
241 | IE = ComedyCentralIE | |
242 | ||
243 | def getInfoDict(self): | |
244 | return super(TestMTVSubtitles, self).getInfoDict()['entries'][0] | |
245 | ||
246 | def test_allsubtitles(self): | |
247 | self.DL.params['writesubtitles'] = True | |
248 | self.DL.params['allsubtitles'] = True | |
249 | subtitles = self.getSubtitles() | |
250 | self.assertEqual(set(subtitles.keys()), set(['en'])) | |
251 | self.assertEqual(md5(subtitles['en']), '78206b8d8a0cfa9da64dc026eea48961') | |
252 | ||
253 | ||
254 | class TestNRKSubtitles(BaseTestSubtitles): | |
255 | url = 'http://tv.nrk.no/serie/ikke-gjoer-dette-hjemme/DMPV73000411/sesong-2/episode-1' | |
256 | IE = NRKTVIE | |
257 | ||
258 | def test_allsubtitles(self): | |
259 | self.DL.params['writesubtitles'] = True | |
260 | self.DL.params['allsubtitles'] = True | |
261 | subtitles = self.getSubtitles() | |
262 | self.assertEqual(set(subtitles.keys()), set(['no'])) | |
263 | self.assertEqual(md5(subtitles['no']), '544fa917d3197fcbee64634559221cc2') | |
264 | ||
265 | ||
266 | class TestRaiPlaySubtitles(BaseTestSubtitles): | |
267 | url = 'http://www.raiplay.it/video/2014/04/Report-del-07042014-cb27157f-9dd0-4aee-b788-b1f67643a391.html' | |
268 | IE = RaiPlayIE | |
269 | ||
270 | def test_allsubtitles(self): | |
271 | self.DL.params['writesubtitles'] = True | |
272 | self.DL.params['allsubtitles'] = True | |
273 | subtitles = self.getSubtitles() | |
274 | self.assertEqual(set(subtitles.keys()), set(['it'])) | |
275 | self.assertEqual(md5(subtitles['it']), 'b1d90a98755126b61e667567a1f6680a') | |
276 | ||
277 | ||
278 | class TestVikiSubtitles(BaseTestSubtitles): | |
279 | url = 'http://www.viki.com/videos/1060846v-punch-episode-18' | |
280 | IE = VikiIE | |
281 | ||
282 | def test_allsubtitles(self): | |
283 | self.DL.params['writesubtitles'] = True | |
284 | self.DL.params['allsubtitles'] = True | |
285 | subtitles = self.getSubtitles() | |
286 | self.assertEqual(set(subtitles.keys()), set(['en'])) | |
287 | self.assertEqual(md5(subtitles['en']), '53cb083a5914b2d84ef1ab67b880d18a') | |
288 | ||
289 | ||
290 | class TestThePlatformSubtitles(BaseTestSubtitles): | |
291 | # from http://www.3playmedia.com/services-features/tools/integrations/theplatform/ | |
292 | # (see http://theplatform.com/about/partners/type/subtitles-closed-captioning/) | |
293 | url = 'theplatform:JFUjUE1_ehvq' | |
294 | IE = ThePlatformIE | |
295 | ||
296 | def test_allsubtitles(self): | |
297 | self.DL.params['writesubtitles'] = True | |
298 | self.DL.params['allsubtitles'] = True | |
299 | subtitles = self.getSubtitles() | |
300 | self.assertEqual(set(subtitles.keys()), set(['en'])) | |
301 | self.assertEqual(md5(subtitles['en']), '97e7670cbae3c4d26ae8bcc7fdd78d4b') | |
302 | ||
303 | ||
304 | class TestThePlatformFeedSubtitles(BaseTestSubtitles): | |
305 | url = 'http://feed.theplatform.com/f/7wvmTC/msnbc_video-p-test?form=json&pretty=true&range=-40&byGuid=n_hardball_5biden_140207' | |
306 | IE = ThePlatformFeedIE | |
307 | ||
308 | def test_allsubtitles(self): | |
309 | self.DL.params['writesubtitles'] = True | |
310 | self.DL.params['allsubtitles'] = True | |
311 | subtitles = self.getSubtitles() | |
312 | self.assertEqual(set(subtitles.keys()), set(['en'])) | |
313 | self.assertEqual(md5(subtitles['en']), '48649a22e82b2da21c9a67a395eedade') | |
314 | ||
315 | ||
316 | class TestRtveSubtitles(BaseTestSubtitles): | |
317 | url = 'http://www.rtve.es/alacarta/videos/los-misterios-de-laura/misterios-laura-capitulo-32-misterio-del-numero-17-2-parte/2428621/' | |
318 | IE = RTVEALaCartaIE | |
319 | ||
320 | def test_allsubtitles(self): | |
321 | print('Skipping, only available from Spain') | |
322 | return | |
323 | self.DL.params['writesubtitles'] = True | |
324 | self.DL.params['allsubtitles'] = True | |
325 | subtitles = self.getSubtitles() | |
326 | self.assertEqual(set(subtitles.keys()), set(['es'])) | |
327 | self.assertEqual(md5(subtitles['es']), '69e70cae2d40574fb7316f31d6eb7fca') | |
328 | ||
329 | ||
330 | class TestDemocracynowSubtitles(BaseTestSubtitles): | |
331 | url = 'http://www.democracynow.org/shows/2015/7/3' | |
332 | IE = DemocracynowIE | |
333 | ||
334 | def test_allsubtitles(self): | |
335 | self.DL.params['writesubtitles'] = True | |
336 | self.DL.params['allsubtitles'] = True | |
337 | subtitles = self.getSubtitles() | |
338 | self.assertEqual(set(subtitles.keys()), set(['en'])) | |
339 | self.assertEqual(md5(subtitles['en']), 'acaca989e24a9e45a6719c9b3d60815c') | |
340 | ||
341 | def test_subtitles_in_page(self): | |
342 | self.url = 'http://www.democracynow.org/2015/7/3/this_flag_comes_down_today_bree' | |
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']), 'acaca989e24a9e45a6719c9b3d60815c') | |
348 | ||
349 | ||
350 | if __name__ == '__main__': | |
351 | unittest.main() |