1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-18 16:26:23 +00:00

Added allow_file_scheme feature

This commit is contained in:
Vladislav Dyshakov 2021-10-17 17:21:25 +07:00
parent a803582717
commit 690a357cc7
No known key found for this signature in database
GPG key ID: BB27F16A285F09F1
2 changed files with 7 additions and 1 deletions

View file

@ -885,6 +885,10 @@ class TestYoutubeDL(unittest.TestCase):
ydl = YDL() ydl = YDL()
self.assertRaises(compat_urllib_error.URLError, ydl.urlopen, 'file:///etc/passwd') self.assertRaises(compat_urllib_error.URLError, ydl.urlopen, 'file:///etc/passwd')
def test_urlopen_yes_file_protocol(self):
ydl = YDL({'allow_file_scheme': True})
ydl.urlopen('file:///etc/passwd')
def test_do_not_override_ie_key_in_url_transparent(self): def test_do_not_override_ie_key_in_url_transparent(self):
ydl = YDL() ydl = YDL()

View file

@ -224,6 +224,7 @@ class YoutubeDL(object):
default_search: Prepend this string if an input url is not valid. default_search: Prepend this string if an input url is not valid.
'auto' for elaborate guessing 'auto' for elaborate guessing
encoding: Use this encoding instead of the system-specified. encoding: Use this encoding instead of the system-specified.
allow_file_scheme: Allow use of file:// scheme.
extract_flat: Do not resolve URLs, return the immediate result. extract_flat: Do not resolve URLs, return the immediate result.
Pass in 'in_playlist' to only show this behavior for Pass in 'in_playlist' to only show this behavior for
playlist items. playlist items.
@ -2404,6 +2405,7 @@ class YoutubeDL(object):
file_handler = compat_urllib_request.FileHandler() file_handler = compat_urllib_request.FileHandler()
def file_open(*args, **kwargs): def file_open(*args, **kwargs):
if not self.params.get('allow_file_scheme', False):
raise compat_urllib_error.URLError('file:// scheme is explicitly disabled in youtube-dl for security reasons') raise compat_urllib_error.URLError('file:// scheme is explicitly disabled in youtube-dl for security reasons')
file_handler.file_open = file_open file_handler.file_open = file_open