From 952b208a016548ad917737848cf3031e3f8af2d6 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Thu, 24 Jan 2019 13:52:33 -0600 Subject: [PATCH] Add retry for /videoplaybacl --- src/invidious.cr | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 1a96b50a..ad9510c1 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -3644,9 +3644,23 @@ get "/videoplayback" do |env| host = "https://r#{fvip}---#{mn}.googlevideo.com" url = "/videoplayback?#{query_params.to_s}" + headers = env.request.headers + headers.delete("Host") + headers.delete("Cookie") + headers.delete("User-Agent") + headers.delete("Referer") + region = query_params["region"]? - client = make_client(URI.parse(host), proxies, region) - response = client.head(url) + + response = HTTP::Client::Response.new(403) + loop do + begin + client = make_client(URI.parse(host), proxies, region) + response = client.head(url, headers) + break + rescue ex + end + end if response.headers["Location"]? url = URI.parse(response.headers["Location"]) @@ -3664,12 +3678,6 @@ get "/videoplayback" do |env| halt env, status_code: 403 end - headers = env.request.headers - headers.delete("Host") - headers.delete("Cookie") - headers.delete("User-Agent") - headers.delete("Referer") - client = make_client(URI.parse(host), proxies, region) client.get(url, headers) do |response| env.response.status_code = response.status_code