summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThéo Gaillard <theo.gaillard@protonmail.com>2020-11-26 07:22:47 +0100
committerThéo Gaillard <theo.gaillard@protonmail.com>2020-11-26 07:22:47 +0100
commit480d31eb5e68c0d90ab8e3f43034484bfc0e158a (patch)
tree6c22a0d6628ccd09cc434e911db9b6bb06d1631b /src
parent1973f93d4a2b54f7284cc407ef05da232272269b (diff)
downloadinvidious-480d31eb5e68c0d90ab8e3f43034484bfc0e158a.tar.gz
invidious-480d31eb5e68c0d90ab8e3f43034484bfc0e158a.tar.bz2
invidious-480d31eb5e68c0d90ab8e3f43034484bfc0e158a.zip
fix: ytInitialData parsing with regex
Diffstat (limited to 'src')
-rw-r--r--src/invidious/helpers/helpers.cr7
1 files changed, 1 insertions, 6 deletions
diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr
index 620d2ec8..7ff68b32 100644
--- a/src/invidious/helpers/helpers.cr
+++ b/src/invidious/helpers/helpers.cr
@@ -598,12 +598,7 @@ def create_notification_stream(env, topics, connection_channel)
end
def extract_initial_data(body) : Hash(String, JSON::Any)
- initial_data = body.match(/(window\["ytInitialData"\]|var\s+ytInitialData)\s*=\s*(?<info>.*?);+\s*\n/).try &.["info"] || "{}"
- if initial_data.starts_with?("JSON.parse(\"")
- return JSON.parse(JSON.parse(%({"initial_data":"#{initial_data[12..-3]}"}))["initial_data"].as_s).as_h
- else
- return JSON.parse(initial_data).as_h
- end
+ return JSON.parse(body.match(/(window\["ytInitialData"\]|var\s*ytInitialData)\s*=\s*(?<info>\{.*?\});/).try &.["info"] || "{}").as_h
end
def proxy_file(response, env)