1
0
mirror of https://github.com/yt-dlp/yt-dlp synced 2025-07-13 09:07:41 -05:00

[extractor] Add _search_json

All fetching of JSON objects should eventually be done with this function
but only `youtube` is being refactored for now
This commit is contained in:
pukkandan
2022-06-03 21:02:31 +05:30
parent 00bbc5f177
commit b7c47b7438
4 changed files with 42 additions and 39 deletions

View File

@ -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.