From aa55e67389ac8c3786c5e0ac4dca3d50f2193e16 Mon Sep 17 00:00:00 2001 From: syeopite Date: Fri, 25 Jun 2021 07:51:51 -0700 Subject: [PATCH] Fix extraction of age restricted videos --- src/invidious/videos.cr | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 116aafc7..5b2158ec 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -989,9 +989,15 @@ def fetch_video(id, region) # Try to pull streams from embed URL if info["reason"]? - embed_page = YT_POOL.client &.get("/embed/#{id}").body - sts = embed_page.match(/"sts"\s*:\s*(?\d+)/).try &.["sts"]? || "" - embed_info = HTTP::Params.parse(YT_POOL.client &.get("/get_video_info?html5=1&video_id=#{id}&eurl=https://youtube.googleapis.com/v/#{id}&gl=US&hl=en&sts=#{sts}").body) + required_parameters = URI::Params.new({ + "video_id" => [id], + "eurl" => ["https://youtube.googleapis.com/v/#{id}"], + "html5" => ["1"], + "c" => ["TVHTML5"], + "cver" => ["6.20180913"], + }) + + embed_info = HTTP::Params.parse(YT_POOL.client &.get("/get_video_info?#{required_parameters}", headers: HTTP::Headers{"x-youtube-client-version" => "6.20180913"}).body) if embed_info["player_response"]? player_response = JSON.parse(embed_info["player_response"])