From 22d9d16a7a3b6a90ff7956822c5a36522da465f9 Mon Sep 17 00:00:00 2001 From: Ben Heller Date: Thu, 22 Oct 2020 03:02:15 -0700 Subject: [PATCH] Update parsing of ytInitialData (#1427) Update parsing of ytInitialData --- src/invidious/helpers/helpers.cr | 2 +- src/invidious/videos.cr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index fb220eab..62c24f3e 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"\]\s*=\s*(?.*?);+\n/).try &.["info"] || "{}" + initial_data = body.match(/(window\["ytInitialData"\]|var\s+ytInitialData)\s*=\s*(?.*?);+\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 diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index e7751fb0..8e314fe0 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -839,7 +839,7 @@ def extract_polymer_config(body) params[f] = player_response[f] if player_response[f]? end - yt_initial_data = body.match(/window\["ytInitialData"\]\s*=\s*(?.*?);\n/) + yt_initial_data = body.match(/(window\["ytInitialData"\]|var\s+ytInitialData)\s*=\s*(?.*?);\s*\n/) .try { |r| JSON.parse(r["info"]).as_h } params["relatedVideos"] = yt_initial_data.try &.["playerOverlays"]?.try &.["playerOverlayRenderer"]?