From 85a5bbd696da793e32556c50b8ae946b9358fe17 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Thu, 26 Oct 2023 17:24:53 -0400 Subject: [PATCH 1/5] Add playlist and start time to the resolve url --- src/invidious/routes/api/v1/misc.cr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/invidious/routes/api/v1/misc.cr b/src/invidious/routes/api/v1/misc.cr index 8a92e160..c23fb0a5 100644 --- a/src/invidious/routes/api/v1/misc.cr +++ b/src/invidious/routes/api/v1/misc.cr @@ -175,6 +175,8 @@ module Invidious::Routes::API::V1::Misc json.object do json.field "ucid", sub_endpoint["browseId"].as_s if sub_endpoint["browseId"]? json.field "videoId", sub_endpoint["videoId"].as_s if sub_endpoint["videoId"]? + json.field "playlistId", sub_endpoint["playlistId"].as_s if sub_endpoint["playlistId"]? + json.field "startTimeSeconds", sub_endpoint["startTimeSeconds"].as_s if sub_endpoint["startTimeSeconds"]? json.field "params", params.try &.as_s json.field "pageType", pageType end From d7901c1e0d1e9b9d36cc35d35f43c91b88ebcce4 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Thu, 26 Oct 2023 17:35:52 -0400 Subject: [PATCH 2/5] type fix --- src/invidious/routes/api/v1/misc.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/invidious/routes/api/v1/misc.cr b/src/invidious/routes/api/v1/misc.cr index c23fb0a5..bad47709 100644 --- a/src/invidious/routes/api/v1/misc.cr +++ b/src/invidious/routes/api/v1/misc.cr @@ -176,7 +176,7 @@ module Invidious::Routes::API::V1::Misc json.field "ucid", sub_endpoint["browseId"].as_s if sub_endpoint["browseId"]? json.field "videoId", sub_endpoint["videoId"].as_s if sub_endpoint["videoId"]? json.field "playlistId", sub_endpoint["playlistId"].as_s if sub_endpoint["playlistId"]? - json.field "startTimeSeconds", sub_endpoint["startTimeSeconds"].as_s if sub_endpoint["startTimeSeconds"]? + json.field "startTimeSeconds", sub_endpoint["startTimeSeconds"].as_i if sub_endpoint["startTimeSeconds"]? json.field "params", params.try &.as_s json.field "pageType", pageType end From 7e267da5beef5981b6db40e7b20f23f5dbd81136 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Thu, 26 Oct 2023 17:48:58 -0400 Subject: [PATCH 3/5] 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 || "" From 3881038a32cde54bb31523adb4bbc8fd5b3d759a Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Thu, 26 Oct 2023 17:51:38 -0400 Subject: [PATCH 4/5] format --- src/invidious/routes/api/v1/misc.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/invidious/routes/api/v1/misc.cr b/src/invidious/routes/api/v1/misc.cr index 47ec977e..c6662e32 100644 --- a/src/invidious/routes/api/v1/misc.cr +++ b/src/invidious/routes/api/v1/misc.cr @@ -163,7 +163,7 @@ module Invidious::Routes::API::V1::Misc 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 || "" From b40cf6544a5e801c387b988f1be4d632fd50db90 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sun, 19 Nov 2023 16:06:29 -0500 Subject: [PATCH 5/5] Revert "Make head request to resolve short urls" This reverts commit 7e267da5beef5981b6db40e7b20f23f5dbd81136. --- src/invidious/routes/api/v1/misc.cr | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/invidious/routes/api/v1/misc.cr b/src/invidious/routes/api/v1/misc.cr index c6662e32..bad47709 100644 --- a/src/invidious/routes/api/v1/misc.cr +++ b/src/invidious/routes/api/v1/misc.cr @@ -159,11 +159,6 @@ 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 || ""