]>
jfr.im git - yt-dlp.git/blob - test/test_youtube_subtitles.py
3b5a53fca13d0710db548d2ce731a54137545a5c
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
):
43 DL
.params
['allsubtitles'] = False
44 DL
.params
['writesubtitles'] = False
46 def test_youtube_no_subtitles(self
):
48 DL
.params
['writesubtitles'] = False
50 info_dict
= IE
.extract('QRS8MkLhQmM')
51 subtitles
= info_dict
[0]['subtitles']
52 self
.assertEqual(subtitles
, None)
53 def test_youtube_subtitles(self
):
55 DL
.params
['writesubtitles'] = True
57 info_dict
= IE
.extract('QRS8MkLhQmM')
58 sub
= info_dict
[0]['subtitles'][0]
59 self
.assertEqual(md5(sub
[2]), '4cd9278a35ba2305f47354ee13472260')
60 def test_youtube_subtitles_it(self
):
62 DL
.params
['writesubtitles'] = True
63 DL
.params
['subtitleslang'] = 'it'
65 info_dict
= IE
.extract('QRS8MkLhQmM')
66 sub
= info_dict
[0]['subtitles'][0]
67 self
.assertEqual(md5(sub
[2]), '164a51f16f260476a05b50fe4c2f161d')
68 def test_youtube_onlysubtitles(self
):
70 DL
.params
['writesubtitles'] = True
71 DL
.params
['onlysubtitles'] = True
73 info_dict
= IE
.extract('QRS8MkLhQmM')
74 sub
= info_dict
[0]['subtitles'][0]
75 self
.assertEqual(md5(sub
[2]), '4cd9278a35ba2305f47354ee13472260')
76 def test_youtube_allsubtitles(self
):
78 DL
.params
['allsubtitles'] = True
80 info_dict
= IE
.extract('QRS8MkLhQmM')
81 subtitles
= info_dict
[0]['subtitles']
82 self
.assertEqual(len(subtitles
), 12)
84 if __name__
== '__main__':