Simplify resolveUrl api call

Co-Authored-By: Samantaz Fox <coding@samantaz.fr>
This commit is contained in:
ChunkyProgrammer 2023-07-27 19:14:34 -04:00
parent e3c365f3d6
commit 734f1b7764
4 changed files with 12 additions and 13 deletions

View file

@ -24,12 +24,12 @@ def fetch_channel_community(ucid, cursor, locale, format, thin_mode)
return extract_channel_community(items, ucid: ucid, locale: locale, format: format, thin_mode: thin_mode) return extract_channel_community(items, ucid: ucid, locale: locale, format: format, thin_mode: thin_mode)
end end
def fetch_channel_community_post(ucid, postId, locale, format, thin_mode, params : String | Nil = nil) def fetch_channel_community_post(ucid, post_id, locale, format, thin_mode, params : String | Nil = nil)
if params.nil? if params.nil?
object = { object = {
"2:string" => "community", "2:string" => "community",
"25:embedded" => { "25:embedded" => {
"22:string" => postId.to_s, "22:string" => post_id.to_s,
}, },
"45:embedded" => { "45:embedded" => {
"2:varint" => 1_i64, "2:varint" => 1_i64,

View file

@ -16,11 +16,11 @@ module Invidious::Comments
return parse_youtube(id, response, format, locale, thin_mode, sort_by) return parse_youtube(id, response, format, locale, thin_mode, sort_by)
end end
def fetch_community_post_comments(ucid, postId) def fetch_community_post_comments(ucid, post_id)
object = { object = {
"2:string" => "community", "2:string" => "community",
"25:embedded" => { "25:embedded" => {
"22:string" => postId, "22:string" => post_id,
}, },
"45:embedded" => { "45:embedded" => {
"2:varint" => 1_i64, "2:varint" => 1_i64,
@ -30,7 +30,7 @@ module Invidious::Comments
"4:embedded" => { "4:embedded" => {
"6:varint" => 0_i64, "6:varint" => 0_i64,
"27:varint" => 1_i64, "27:varint" => 1_i64,
"29:string" => postId, "29:string" => post_id,
"30:string" => ucid, "30:string" => ucid,
}, },
"8:string" => "comments-section", "8:string" => "comments-section",

View file

@ -162,16 +162,15 @@ module Invidious::Routes::API::V1::Misc
resolved_url = YoutubeAPI.resolve_url(url.as(String)) resolved_url = YoutubeAPI.resolve_url(url.as(String))
endpoint = resolved_url["endpoint"] endpoint = resolved_url["endpoint"]
pageType = endpoint.dig?("commandMetadata", "webCommandMetadata", "webPageType").try &.as_s || "" pageType = endpoint.dig?("commandMetadata", "webCommandMetadata", "webPageType").try &.as_s || ""
if sub_endpoint = endpoint.dig?("watchEndpoint") if sub_endpoint = endpoint["watchEndpoint"]?
resolved_ucid = sub_endpoint.dig?("videoId") resolved_ucid = sub_endpoint["videoId"]?
elsif sub_endpoint = endpoint.dig?("browseEndpoint") elsif sub_endpoint = endpoint["browseEndpoint"]?
resolved_ucid = sub_endpoint.dig?("browseId") resolved_ucid = sub_endpoint["browseId"]?
elsif pageType == "WEB_PAGE_TYPE_UNKNOWN" elsif pageType == "WEB_PAGE_TYPE_UNKNOWN"
return error_json(400, "Unknown url") return error_json(400, "Unknown url")
end end
if !sub_endpoint.nil?
params = sub_endpoint.dig?("params") params = sub_endpoint.try &.dig?("params")
end
rescue ex rescue ex
return error_json(500, ex) return error_json(500, ex)
end end

View file

@ -161,7 +161,7 @@ module Invidious::Routes::Channels
# redirect to post page # redirect to post page
if lb = env.params.query["lb"]? if lb = env.params.query["lb"]?
env.redirect "/post/#{lb}?ucid=#{ucid}" env.redirect "/post/#{URI.encode_www_form(lb)}?ucid=#{URI.encode_www_form(ucid)}"
end end
thin_mode = env.params.query["thin_mode"]? || env.get("preferences").as(Preferences).thin_mode thin_mode = env.params.query["thin_mode"]? || env.get("preferences").as(Preferences).thin_mode