From a4f923839a70b219fc45998c4fd30f1ac1a09b5d Mon Sep 17 00:00:00 2001 From: saltycrys <73420320+saltycrys@users.noreply.github.com> Date: Thu, 26 Nov 2020 10:39:07 +0100 Subject: [PATCH] Fix ytInitialData parsing For some reason Ruby and Crystal add PCRE_DOTALL to the "m" flag which is supposed to be PCRE_MULTILINE. I guess that makes sense, but it's nonstandard and I had to read the Crystal source to figure it out. See https://github.com/crystal-lang/crystal/blob/4c88b8b69babbcb877169f3e3b9dcf1d9ff189a0/src/regex/regex.cr#L10 --- src/invidious/helpers/helpers.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 62c24f3e..e3a47072 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -597,7 +597,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*(?.*?);+\s*\n/).try &.["info"] || "{}" + initial_data = body.match(/(window\["ytInitialData"\]|var\s+ytInitialData)\s*=\s*(?.*?);+(\s*\n|<\/script>)/m).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