From b7c47b743871cdf3e0de75b17e4454d987384bf9 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Fri, 3 Jun 2022 21:02:31 +0530 Subject: [extractor] Add `_search_json` All fetching of JSON objects should eventually be done with this function but only `youtube` is being refactored for now --- yt_dlp/utils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'yt_dlp/utils.py') 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. -- cgit v1.2.3