mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-18 00:05:22 +01:00
[extractor/common] Respect default in _search_json_ld
This commit is contained in:
parent
3711fa1eb2
commit
321b5e082a
|
@ -816,11 +816,14 @@ def _search_json_ld(self, html, video_id, expected_type=None, **kwargs):
|
||||||
json_ld = self._search_regex(
|
json_ld = self._search_regex(
|
||||||
r'(?s)<script[^>]+type=(["\'])application/ld\+json\1[^>]*>(?P<json_ld>.+?)</script>',
|
r'(?s)<script[^>]+type=(["\'])application/ld\+json\1[^>]*>(?P<json_ld>.+?)</script>',
|
||||||
html, 'JSON-LD', group='json_ld', **kwargs)
|
html, 'JSON-LD', group='json_ld', **kwargs)
|
||||||
|
default = kwargs.get('default', NO_DEFAULT)
|
||||||
if not json_ld:
|
if not json_ld:
|
||||||
return {}
|
return default if default is not NO_DEFAULT else {}
|
||||||
return self._json_ld(
|
# JSON-LD may be malformed and thus `fatal` should be respected.
|
||||||
json_ld, video_id, fatal=kwargs.get('fatal', True),
|
# At the same time `default` may be passed that assumes `fatal=False`
|
||||||
expected_type=expected_type)
|
# for _search_regex. Let's simulate the same behavior here as well.
|
||||||
|
fatal = kwargs.get('fatal', True) if default == NO_DEFAULT else False
|
||||||
|
return self._json_ld(json_ld, video_id, fatal=fatal, expected_type=expected_type)
|
||||||
|
|
||||||
def _json_ld(self, json_ld, video_id, fatal=True, expected_type=None):
|
def _json_ld(self, json_ld, video_id, fatal=True, expected_type=None):
|
||||||
if isinstance(json_ld, compat_str):
|
if isinstance(json_ld, compat_str):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user