From f55523cfdd18dcd578f5d96cbb06266663169d35 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Fri, 23 Sep 2022 19:21:07 +0530 Subject: [PATCH] [utils] `js_to_json`: Improve Closes #4900 --- yt_dlp/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index 26ef3c7dd1..f6ab9905d4 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -3298,7 +3298,7 @@ def js_to_json(code, vars={}, *, strict=False): return '"%d":' % i if v.endswith(':') else '%d' % i if v in vars: - return vars[v] + return json.dumps(vars[v]) if strict: raise ValueError(f'Unknown value: {v}') @@ -3310,6 +3310,7 @@ def js_to_json(code, vars={}, *, strict=False): code = re.sub(r'new Map\((\[.*?\])?\)', create_map, code) if not strict: code = re.sub(r'new Date\((".+")\)', r'\g<1>', code) + code = re.sub(r'new \w+\((.*?)\)', lambda m: json.dumps(m.group(0)), code) return re.sub(r'''(?sx) "(?:[^"\\]*(?:\\\\|\\['"nurtbfx/\n]))*[^"\\]*"|