mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-05 20:47:07 +01:00
[extractor/common] Fix json_ld
type checks (#5145)
Closes #5144, #5143 Authored by: Grub4K
This commit is contained in:
parent
f324fe8c59
commit
1d55ebabc9
@ -1467,10 +1467,6 @@ def _json_ld(self, json_ld, video_id, fatal=True, expected_type=None):
|
|||||||
if not json_ld:
|
if not json_ld:
|
||||||
return {}
|
return {}
|
||||||
info = {}
|
info = {}
|
||||||
if not isinstance(json_ld, (list, tuple, dict)):
|
|
||||||
return info
|
|
||||||
if isinstance(json_ld, dict):
|
|
||||||
json_ld = [json_ld]
|
|
||||||
|
|
||||||
INTERACTION_TYPE_MAP = {
|
INTERACTION_TYPE_MAP = {
|
||||||
'CommentAction': 'comment',
|
'CommentAction': 'comment',
|
||||||
@ -1570,11 +1566,13 @@ def extract_video_object(e):
|
|||||||
extract_chapter_information(e)
|
extract_chapter_information(e)
|
||||||
|
|
||||||
def traverse_json_ld(json_ld, at_top_level=True):
|
def traverse_json_ld(json_ld, at_top_level=True):
|
||||||
for e in json_ld:
|
for e in variadic(json_ld):
|
||||||
|
if not isinstance(e, dict):
|
||||||
|
continue
|
||||||
if at_top_level and '@context' not in e:
|
if at_top_level and '@context' not in e:
|
||||||
continue
|
continue
|
||||||
if at_top_level and set(e.keys()) == {'@context', '@graph'}:
|
if at_top_level and set(e.keys()) == {'@context', '@graph'}:
|
||||||
traverse_json_ld(variadic(e['@graph'], allowed_types=(dict,)), at_top_level=False)
|
traverse_json_ld(e['@graph'], at_top_level=False)
|
||||||
break
|
break
|
||||||
if expected_type is not None and not is_type(e, expected_type):
|
if expected_type is not None and not is_type(e, expected_type):
|
||||||
continue
|
continue
|
||||||
@ -1629,8 +1627,8 @@ def traverse_json_ld(json_ld, at_top_level=True):
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
traverse_json_ld(json_ld)
|
|
||||||
|
|
||||||
|
traverse_json_ld(json_ld)
|
||||||
return filter_dict(info)
|
return filter_dict(info)
|
||||||
|
|
||||||
def _search_nextjs_data(self, webpage, video_id, *, transform_source=None, fatal=True, **kw):
|
def _search_nextjs_data(self, webpage, video_id, *, transform_source=None, fatal=True, **kw):
|
||||||
|
@ -2463,6 +2463,21 @@ class GenericIE(InfoExtractor):
|
|||||||
'duration': 111.0,
|
'duration': 111.0,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'note': 'JSON LD with unexpected data type',
|
||||||
|
'url': 'https://www.autoweek.nl/autotests/artikel/porsche-911-gt3-rs-rij-impressie-2/',
|
||||||
|
'info_dict': {
|
||||||
|
'id': 'porsche-911-gt3-rs-rij-impressie-2',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'title': 'Test: Porsche 911 GT3 RS',
|
||||||
|
'description': 'Je ziet het niet, maar het is er wel. Downforce, hebben we het dan over. En in de nieuwe Porsche 911 GT3 RS is er zelfs heel veel downforce.',
|
||||||
|
'timestamp': 1664920902,
|
||||||
|
'upload_date': '20221004',
|
||||||
|
'thumbnail': r're:^https://media.autoweek.nl/m/.+\.jpg$',
|
||||||
|
'age_limit': 0,
|
||||||
|
'direct': True,
|
||||||
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
def report_following_redirect(self, new_url):
|
def report_following_redirect(self, new_url):
|
||||||
|
Loading…
Reference in New Issue
Block a user