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:
@ -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.
|
||||
|
||||
|
Reference in New Issue
Block a user