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 4c88b8b69b/src/regex/regex.cr (L10)
This commit is contained in:
saltycrys 2020-11-26 10:39:07 +01:00
parent aeed7deb2d
commit a4f923839a

View File

@ -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*(?<info>.*?);+\s*\n/).try &.["info"] || "{}"
initial_data = body.match(/(window\["ytInitialData"\]|var\s+ytInitialData)\s*=\s*(?<info>.*?);+(\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