mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-14 04:13:20 +00:00
function for lambda
This commit is contained in:
parent
d5b48c06e6
commit
1d851a6751
|
@ -1293,6 +1293,9 @@ def parse_model(model):
|
|||
})
|
||||
}
|
||||
|
||||
def is_type(*types):
|
||||
return lambda _, v: v['type'] in types
|
||||
|
||||
initial_data = self._search_regex(
|
||||
r'window\.__INITIAL_DATA__\s*=\s*("{.+?}")\s*;', webpage,
|
||||
'quoted preload state', default=None)
|
||||
|
@ -1305,10 +1308,10 @@ def parse_model(model):
|
|||
initial_data = self._parse_json(initial_data, playlist_id, fatal=False)
|
||||
if initial_data:
|
||||
for video_data in traverse_obj(initial_data, (
|
||||
'stores', 'article', 'articleBodyContent', lambda _, v: v['type'] == 'video')):
|
||||
'stores', 'article', 'articleBodyContent', is_type('video'))):
|
||||
model = traverse_obj(video_data, (
|
||||
'model', 'blocks', lambda _, v: v['type'] == 'aresMedia',
|
||||
'model', 'blocks', lambda _, v: v['type'] == 'aresMediaMetadata',
|
||||
'model', 'blocks', is_type('aresMedia'),
|
||||
'model', 'blocks', is_type('aresMediaMetadata'),
|
||||
'model', {dict}, any))
|
||||
entry = parse_model(model)
|
||||
if entry:
|
||||
|
@ -1374,15 +1377,15 @@ def extract_all(pattern):
|
|||
next_data = traverse_obj(self._search_nextjs_data(webpage, playlist_id, default={}),
|
||||
('props', 'pageProps', 'page'))
|
||||
model = traverse_obj(next_data, (
|
||||
..., 'contents', lambda _, v: v['type'] == 'video',
|
||||
'model', 'blocks', lambda _, v: v['type'] == 'media',
|
||||
'model', 'blocks', lambda _, v: v['type'] == 'mediaMetadata',
|
||||
..., 'contents', is_type('video'),
|
||||
'model', 'blocks', is_type('media'),
|
||||
'model', 'blocks', is_type('mediaMetadata'),
|
||||
'model', {dict}, any))
|
||||
if model:
|
||||
if entry := parse_model(model):
|
||||
if not entry.get('timestamp'):
|
||||
entry['timestamp'] = traverse_obj(next_data, (
|
||||
..., 'contents', lambda _, v: v['type'] == 'timestamp',
|
||||
..., 'contents', is_type('timestamp'),
|
||||
'model', 'timestamp', {k_int_or_none}, any))
|
||||
entries.append(entry)
|
||||
return self.playlist_result(
|
||||
|
|
Loading…
Reference in a new issue