mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-07-29 00:28:29 +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):
|
if not isinstance(data, dict):
|
||||||
return
|
return
|
||||||
children = data.pop('children', None)
|
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
|
# It is useful hydration JSON data
|
||||||
nextjs_data.append(data)
|
nextjs_data.append(data)
|
||||||
flatten(children)
|
flatten(children)
|
||||||
@ -1806,6 +1806,7 @@ def flatten(flight_data):
|
|||||||
for f in flight_data:
|
for f in flight_data:
|
||||||
flatten(f)
|
flatten(f)
|
||||||
|
|
||||||
|
flight_text = ''
|
||||||
# The flight segments regex pattern can afford to be (and should be) strict
|
# The flight segments regex pattern can afford to be (and should be) strict
|
||||||
# Ref: https://github.com/vercel/next.js/commit/5a4a08fdce91a038f2ed3a70568d3ed040403150
|
# Ref: https://github.com/vercel/next.js/commit/5a4a08fdce91a038f2ed3a70568d3ed040403150
|
||||||
# /packages/next/src/server/app-render/use-flight-response.tsx
|
# /packages/next/src/server/app-render/use-flight-response.tsx
|
||||||
@ -1830,10 +1831,14 @@ def flatten(flight_data):
|
|||||||
elif payload_type != 1:
|
elif payload_type != 1:
|
||||||
# Ignore useless payload types (0: bootstrap, 2: form state)
|
# Ignore useless payload types (0: bootstrap, 2: form state)
|
||||||
continue
|
continue
|
||||||
# Not all chunks are complete JSON data; this should always be non-fatal
|
flight_text += chunk
|
||||||
flatten(self._search_json(
|
|
||||||
r'^[\da-f]+:', chunk, 'flight data', video_id,
|
for f in flight_text.splitlines():
|
||||||
default=None, contains_pattern=r'\[.+\]'))
|
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
|
return nextjs_data
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user