mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-07-27 07:38:30 +00:00
refactor
Authored by: bashonly
This commit is contained in:
parent
e2f25c0588
commit
f383c0b600
@ -1798,7 +1798,7 @@ def flatten(flight_data):
|
||||
if not isinstance(data, dict):
|
||||
return
|
||||
children = data.pop('children', None)
|
||||
if data and isinstance(name, str) and name[:1] == '$':
|
||||
if data and isinstance(name, str) and name.startswith('$'):
|
||||
# It is useful hydration JSON data
|
||||
nextjs_data.append(data)
|
||||
flatten(children)
|
||||
@ -1806,6 +1806,7 @@ def flatten(flight_data):
|
||||
for f in flight_data:
|
||||
flatten(f)
|
||||
|
||||
flight_text = ''
|
||||
# The flight segments regex pattern can afford to be (and should be) strict
|
||||
# Ref: https://github.com/vercel/next.js/commit/5a4a08fdce91a038f2ed3a70568d3ed040403150
|
||||
# /packages/next/src/server/app-render/use-flight-response.tsx
|
||||
@ -1830,10 +1831,14 @@ def flatten(flight_data):
|
||||
elif payload_type != 1:
|
||||
# Ignore useless payload types (0: bootstrap, 2: form state)
|
||||
continue
|
||||
# Not all chunks are complete JSON data; this should always be non-fatal
|
||||
flatten(self._search_json(
|
||||
r'^[\da-f]+:', chunk, 'flight data', video_id,
|
||||
default=None, contains_pattern=r'\[.+\]'))
|
||||
flight_text += chunk
|
||||
|
||||
for f in flight_text.splitlines():
|
||||
prefix, _, body = f.partition(':')
|
||||
if not (body.startswith('[') and body.endswith(']') and re.fullmatch(r'[0-9a-f]{1,3}', prefix)):
|
||||
continue
|
||||
# The body isn't necessarily valid JSON; this should always be non-fatal
|
||||
flatten(self._parse_json(body, video_id, fatal=False, errnote=False))
|
||||
|
||||
return nextjs_data
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user