From 690a357cc77b8f8e82321d6eaee1c2101a607edd Mon Sep 17 00:00:00 2001 From: Vladislav Dyshakov Date: Sun, 17 Oct 2021 17:21:25 +0700 Subject: [PATCH] Added allow_file_scheme feature --- test/test_YoutubeDL.py | 4 ++++ youtube_dl/YoutubeDL.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/test/test_YoutubeDL.py b/test/test_YoutubeDL.py index a35effe0e..8e16d2ccc 100644 --- a/test/test_YoutubeDL.py +++ b/test/test_YoutubeDL.py @@ -885,6 +885,10 @@ class TestYoutubeDL(unittest.TestCase): ydl = YDL() 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): ydl = YDL() diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index fe30758ef..f9c61b2d3 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -224,6 +224,7 @@ class YoutubeDL(object): default_search: Prepend this string if an input url is not valid. 'auto' for elaborate guessing 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. Pass in 'in_playlist' to only show this behavior for playlist items. @@ -2404,7 +2405,8 @@ class YoutubeDL(object): file_handler = compat_urllib_request.FileHandler() def file_open(*args, **kwargs): - raise compat_urllib_error.URLError('file:// scheme is explicitly disabled in youtube-dl for security reasons') + 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') file_handler.file_open = file_open opener = compat_urllib_request.build_opener(