mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-09-06 02:49:35 +02:00
harden regex with lookbehind
This commit is contained in:
parent
eaedbfd97e
commit
15eae44d74
@ -28,8 +28,8 @@ def dl_fragment(url):
|
||||
return self._download_fragment(ctx, url, info_dict, headers)
|
||||
|
||||
def parse_yt_initial_data(data):
|
||||
window_patt = b'window\\["ytInitialData"\\]\\s*=\\s*(.*?);'
|
||||
var_patt = b'var\\s+ytInitialData\\s*=\\s*(.*?);'
|
||||
window_patt = b'window\\["ytInitialData"\\]\\s*=\\s*(.*?)(?<=});'
|
||||
var_patt = b'var\\s+ytInitialData\\s*=\\s*(.*?)(?<=});'
|
||||
for patt in window_patt, var_patt:
|
||||
try:
|
||||
raw_json = re.search(patt, data).group(1)
|
||||
|
@ -1495,8 +1495,8 @@ def _get_ytplayer_config(self, video_id, webpage):
|
||||
|
||||
def _get_yt_initial_data(self, video_id, webpage):
|
||||
config = self._search_regex(
|
||||
(r'window\["ytInitialData"\]\s*=\s*(.*);',
|
||||
r'var\s+ytInitialData\s*=\s*(.*?);'),
|
||||
(r'window\["ytInitialData"\]\s*=\s*(.*?)(?<=});',
|
||||
r'var\s+ytInitialData\s*=\s*(.*?)(?<=});'),
|
||||
webpage, 'ytInitialData', default=None)
|
||||
if config:
|
||||
return self._parse_json(
|
||||
|
Loading…
Reference in New Issue
Block a user