From 7e267da5beef5981b6db40e7b20f23f5dbd81136 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Thu, 26 Oct 2023 17:48:58 -0400 Subject: [PATCH] Make head request to resolve short urls --- src/invidious/routes/api/v1/misc.cr | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/invidious/routes/api/v1/misc.cr b/src/invidious/routes/api/v1/misc.cr index bad47709..47ec977e 100644 --- a/src/invidious/routes/api/v1/misc.cr +++ b/src/invidious/routes/api/v1/misc.cr @@ -159,6 +159,11 @@ module Invidious::Routes::API::V1::Misc return error_json(400, "Missing URL to resolve") if !url begin + head_response = HTTP::Client.head url.as(String) + if head_response.headers["location"]? + url = head_response.headers["location"] + end + resolved_url = YoutubeAPI.resolve_url(url.as(String)) endpoint = resolved_url["endpoint"] pageType = endpoint.dig?("commandMetadata", "webCommandMetadata", "webPageType").try &.as_s || ""