]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_subtitles.py
23a6531248ccd162155d61bcc3ac5621fb08a8f2
3 # Allow direct execution
7 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
9 from test
.helper
import FakeYDL
, md5
12 from youtube_dl
.extractor
import (
19 class BaseTestSubtitles(unittest
.TestCase
):
24 self
.ie
= self
.IE(self
.DL
)
26 def getInfoDict(self
):
27 info_dict
= self
.ie
.extract(self
.url
)
30 def getSubtitles(self
):
31 info_dict
= self
.getInfoDict()
32 return info_dict
['subtitles']
35 class TestYoutubeSubtitles(BaseTestSubtitles
):
39 def getSubtitles(self
):
40 info_dict
= self
.getInfoDict()
41 return info_dict
[0]['subtitles']
43 def test_youtube_no_writesubtitles(self
):
44 self
.DL
.params
['writesubtitles'] = False
45 subtitles
= self
.getSubtitles()
46 self
.assertEqual(subtitles
, None)
48 def test_youtube_subtitles(self
):
49 self
.DL
.params
['writesubtitles'] = True
50 subtitles
= self
.getSubtitles()
51 self
.assertEqual(md5(subtitles
['en']), '4cd9278a35ba2305f47354ee13472260')
53 def test_youtube_subtitles_lang(self
):
54 self
.DL
.params
['writesubtitles'] = True
55 self
.DL
.params
['subtitleslangs'] = ['it']
56 subtitles
= self
.getSubtitles()
57 self
.assertEqual(md5(subtitles
['it']), '164a51f16f260476a05b50fe4c2f161d')
59 def test_youtube_allsubtitles(self
):
60 self
.DL
.params
['writesubtitles'] = True
61 self
.DL
.params
['allsubtitles'] = True
62 subtitles
= self
.getSubtitles()
63 self
.assertEqual(len(subtitles
.keys()), 13)
65 def test_youtube_subtitles_sbv_format(self
):
66 self
.DL
.params
['writesubtitles'] = True
67 self
.DL
.params
['subtitlesformat'] = 'sbv'
68 subtitles
= self
.getSubtitles()
69 self
.assertEqual(md5(subtitles
['en']), '13aeaa0c245a8bed9a451cb643e3ad8b')
71 def test_youtube_subtitles_vtt_format(self
):
72 self
.DL
.params
['writesubtitles'] = True
73 self
.DL
.params
['subtitlesformat'] = 'vtt'
74 subtitles
= self
.getSubtitles()
75 self
.assertEqual(md5(subtitles
['en']), '3cb210999d3e021bd6c7f0ea751eab06')
77 def test_youtube_list_subtitles(self
):
78 self
.DL
.expect_warning(u
'Video doesn\'t have automatic captions')
79 self
.DL
.params
['listsubtitles'] = True
80 info_dict
= self
.getInfoDict()
81 self
.assertEqual(info_dict
, None)
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_nosubtitles(self
):
91 self
.DL
.expect_warning(u
'video doesn\'t have subtitles')
92 self
.url
= 'sAjKT8FhjI8'
93 self
.DL
.params
['writesubtitles'] = True
94 self
.DL
.params
['allsubtitles'] = True
95 subtitles
= self
.getSubtitles()
96 self
.assertEqual(len(subtitles
), 0)
98 def test_youtube_multiple_langs(self
):
99 self
.url
= 'QRS8MkLhQmM'
100 self
.DL
.params
['writesubtitles'] = True
101 langs
= ['it', 'fr', 'de']
102 self
.DL
.params
['subtitleslangs'] = langs
103 subtitles
= self
.getSubtitles()
105 self
.assertTrue(subtitles
.get(lang
) is not None, u
'Subtitles for \'%s\' not extracted' % lang
)
108 class TestDailymotionSubtitles(BaseTestSubtitles
):
109 url
= 'http://www.dailymotion.com/video/xczg00'
112 def test_no_writesubtitles(self
):
113 subtitles
= self
.getSubtitles()
114 self
.assertEqual(subtitles
, None)
116 def test_subtitles(self
):
117 self
.DL
.params
['writesubtitles'] = True
118 subtitles
= self
.getSubtitles()
119 self
.assertEqual(md5(subtitles
['en']), '976553874490cba125086bbfea3ff76f')
121 def test_subtitles_lang(self
):
122 self
.DL
.params
['writesubtitles'] = True
123 self
.DL
.params
['subtitleslangs'] = ['fr']
124 subtitles
= self
.getSubtitles()
125 self
.assertEqual(md5(subtitles
['fr']), '594564ec7d588942e384e920e5341792')
127 def test_allsubtitles(self
):
128 self
.DL
.params
['writesubtitles'] = True
129 self
.DL
.params
['allsubtitles'] = True
130 subtitles
= self
.getSubtitles()
131 self
.assertEqual(len(subtitles
.keys()), 5)
133 def test_list_subtitles(self
):
134 self
.DL
.expect_warning(u
'Automatic Captions not supported by this server')
135 self
.DL
.params
['listsubtitles'] = True
136 info_dict
= self
.getInfoDict()
137 self
.assertEqual(info_dict
, None)
139 def test_automatic_captions(self
):
140 self
.DL
.expect_warning(u
'Automatic Captions not supported by this server')
141 self
.DL
.params
['writeautomaticsub'] = True
142 self
.DL
.params
['subtitleslang'] = ['en']
143 subtitles
= self
.getSubtitles()
144 self
.assertTrue(len(subtitles
.keys()) == 0)
146 def test_nosubtitles(self
):
147 self
.DL
.expect_warning(u
'video doesn\'t have subtitles')
148 self
.url
= 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
149 self
.DL
.params
['writesubtitles'] = True
150 self
.DL
.params
['allsubtitles'] = True
151 subtitles
= self
.getSubtitles()
152 self
.assertEqual(len(subtitles
), 0)
154 def test_multiple_langs(self
):
155 self
.DL
.params
['writesubtitles'] = True
156 langs
= ['es', 'fr', 'de']
157 self
.DL
.params
['subtitleslangs'] = langs
158 subtitles
= self
.getSubtitles()
160 self
.assertTrue(subtitles
.get(lang
) is not None, u
'Subtitles for \'%s\' not extracted' % lang
)
163 class TestTedSubtitles(BaseTestSubtitles
):
164 url
= 'http://www.ted.com/talks/dan_dennett_on_our_consciousness.html'
167 def test_no_writesubtitles(self
):
168 subtitles
= self
.getSubtitles()
169 self
.assertEqual(subtitles
, None)
171 def test_subtitles(self
):
172 self
.DL
.params
['writesubtitles'] = True
173 subtitles
= self
.getSubtitles()
174 self
.assertEqual(md5(subtitles
['en']), '2154f31ff9b9f89a0aa671537559c21d')
176 def test_subtitles_lang(self
):
177 self
.DL
.params
['writesubtitles'] = True
178 self
.DL
.params
['subtitleslangs'] = ['fr']
179 subtitles
= self
.getSubtitles()
180 self
.assertEqual(md5(subtitles
['fr']), '7616cbc6df20ec2c1204083c83871cf6')
182 def test_allsubtitles(self
):
183 self
.DL
.params
['writesubtitles'] = True
184 self
.DL
.params
['allsubtitles'] = True
185 subtitles
= self
.getSubtitles()
186 self
.assertEqual(len(subtitles
.keys()), 28)
188 def test_list_subtitles(self
):
189 self
.DL
.expect_warning(u
'Automatic Captions not supported by this server')
190 self
.DL
.params
['listsubtitles'] = True
191 info_dict
= self
.getInfoDict()
192 self
.assertEqual(info_dict
, None)
194 def test_automatic_captions(self
):
195 self
.DL
.expect_warning(u
'Automatic Captions not supported by this server')
196 self
.DL
.params
['writeautomaticsub'] = True
197 self
.DL
.params
['subtitleslang'] = ['en']
198 subtitles
= self
.getSubtitles()
199 self
.assertTrue(len(subtitles
.keys()) == 0)
201 def test_multiple_langs(self
):
202 self
.DL
.params
['writesubtitles'] = True
203 langs
= ['es', 'fr', 'de']
204 self
.DL
.params
['subtitleslangs'] = langs
205 subtitles
= self
.getSubtitles()
207 self
.assertTrue(subtitles
.get(lang
) is not None, u
'Subtitles for \'%s\' not extracted' % lang
)
209 if __name__
== '__main__':