9 # Allow direct execution
11 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
13 from youtube_dl.InfoExtractors import YoutubeIE
14 from youtube_dl.utils import *
16 PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
17 with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
18 parameters = json.load(pf)
20 # General configuration (from __init__, not very elegant...)
21 jar = compat_cookiejar.CookieJar()
22 cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
23 proxy_handler = compat_urllib_request.ProxyHandler()
24 opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
25 compat_urllib_request.install_opener(opener)
27 class FakeDownloader(object):
30 self.params = parameters
31 def to_screen(self, s):
35 def download(self, x):
38 md5 = lambda s: hashlib.md5(s.encode('utf-8')).hexdigest()
40 class TestYoutubeSubtitles(unittest.TestCase):
41 def test_youtube_subtitles(self):
43 DL.params['writesubtitles'] = True
45 info_dict = IE.extract('QRS8MkLhQmM')
46 self.assertEqual(md5(info_dict[0]['subtitles']), 'c3228550d59116f3c29fba370b55d033')
48 def test_youtube_subtitles_it(self):
50 DL.params['writesubtitles'] = True
51 DL.params['subtitleslang'] = 'it'
53 info_dict = IE.extract('QRS8MkLhQmM')
54 self.assertEqual(md5(info_dict[0]['subtitles']), '132a88a0daf8e1520f393eb58f1f646a')
56 if __name__ == '__main__':