diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-06-03 21:02:31 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-06-06 19:46:45 +0530 |
commit | b7c47b743871cdf3e0de75b17e4454d987384bf9 (patch) | |
tree | 928081bf818ee21df40d465c8ffce0bc9ae0ddc2 /yt_dlp/utils.py | |
parent | 00bbc5f17710367adc7508062e155547b35edd20 (diff) | |
download | hypervideo-pre-b7c47b743871cdf3e0de75b17e4454d987384bf9.tar.lz hypervideo-pre-b7c47b743871cdf3e0de75b17e4454d987384bf9.tar.xz hypervideo-pre-b7c47b743871cdf3e0de75b17e4454d987384bf9.zip |
[extractor] Add `_search_json`
All fetching of JSON objects should eventually be done with this function
but only `youtube` is being refactored for now
Diffstat (limited to 'yt_dlp/utils.py')
-rw-r--r-- | yt_dlp/utils.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index 00721eb46..777b8b3ea 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -594,6 +594,19 @@ def clean_html(html): return html.strip() +class LenientJSONDecoder(json.JSONDecoder): + def __init__(self, *args, transform_source=None, ignore_extra=False, **kwargs): + self.transform_source, self.ignore_extra = transform_source, ignore_extra + super().__init__(*args, **kwargs) + + def decode(self, s): + if self.transform_source: + s = self.transform_source(s) + if self.ignore_extra: + return self.raw_decode(s.lstrip())[0] + return super().decode(s) + + def sanitize_open(filename, open_mode): """Try to open the given filename, and slightly tweak it if this fails. |