forked from midou/invidious
Apply suggestions from code review
add videoId to resolve_url function Co-Authored-By: Samantaz Fox <coding@samantaz.fr>
This commit is contained in:
parent
f55b96a53b
commit
bb04bcc42c
@ -37,14 +37,14 @@ module Invidious::Comments
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
objectParsed = object.try { |i| Protodec::Any.cast_json(i) }
|
object_parsed = object.try { |i| Protodec::Any.cast_json(i) }
|
||||||
.try { |i| Protodec::Any.from_json(i) }
|
.try { |i| Protodec::Any.from_json(i) }
|
||||||
.try { |i| Base64.urlsafe_encode(i) }
|
.try { |i| Base64.urlsafe_encode(i) }
|
||||||
|
|
||||||
object2 = {
|
object2 = {
|
||||||
"80226972:embedded" => {
|
"80226972:embedded" => {
|
||||||
"2:string" => ucid,
|
"2:string" => ucid,
|
||||||
"3:string" => objectParsed,
|
"3:string" => object_parsed,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,9 +347,8 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
locale = env.get("preferences").as(Preferences).locale
|
locale = env.get("preferences").as(Preferences).locale
|
||||||
|
|
||||||
env.response.content_type = "application/json"
|
env.response.content_type = "application/json"
|
||||||
|
|
||||||
id = env.params.url["id"].to_s
|
id = env.params.url["id"].to_s
|
||||||
ucid = env.params.query["ucid"]
|
ucid = env.params.query["ucid"]?
|
||||||
|
|
||||||
thin_mode = env.params.query["thin_mode"]?
|
thin_mode = env.params.query["thin_mode"]?
|
||||||
thin_mode = thin_mode == "true"
|
thin_mode = thin_mode == "true"
|
||||||
@ -357,6 +356,14 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
format = env.params.query["format"]?
|
format = env.params.query["format"]?
|
||||||
format ||= "json"
|
format ||= "json"
|
||||||
|
|
||||||
|
if ucid.nil?
|
||||||
|
response = YoutubeAPI.resolve_url("https://www.youtube.com/post/#{id}")
|
||||||
|
return error_json(400, "Invalid post ID") if response["error"]?
|
||||||
|
ucid = response.dig("endpoint", "browseEndpoint", "browseId").as_s
|
||||||
|
else
|
||||||
|
ucid = ucid.to_s
|
||||||
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
fetch_channel_community_post(ucid, id, locale, format, thin_mode)
|
fetch_channel_community_post(ucid, id, locale, format, thin_mode)
|
||||||
rescue ex
|
rescue ex
|
||||||
|
@ -162,21 +162,19 @@ 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["watchEndpoint"]?
|
if pageType == "WEB_PAGE_TYPE_UNKNOWN"
|
||||||
resolved_ucid = sub_endpoint["videoId"]?
|
|
||||||
elsif sub_endpoint = endpoint["browseEndpoint"]?
|
|
||||||
resolved_ucid = sub_endpoint["browseId"]?
|
|
||||||
elsif pageType == "WEB_PAGE_TYPE_UNKNOWN"
|
|
||||||
return error_json(400, "Unknown url")
|
return error_json(400, "Unknown url")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sub_endpoint = endpoint["watchEndpoint"]? || endpoint["browseEndpoint"]? || endpoint
|
||||||
params = sub_endpoint.try &.dig?("params")
|
params = sub_endpoint.try &.dig?("params")
|
||||||
rescue ex
|
rescue ex
|
||||||
return error_json(500, ex)
|
return error_json(500, ex)
|
||||||
end
|
end
|
||||||
JSON.build do |json|
|
JSON.build do |json|
|
||||||
json.object do
|
json.object do
|
||||||
json.field "ucid", resolved_ucid.try &.as_s || ""
|
json.field "ucid", sub_endpoint["browseId"].try &.as_s if sub_endpoint["browseId"]?
|
||||||
|
json.field "videoId", sub_endpoint["videoId"].try &.as_s if sub_endpoint["videoId"]?
|
||||||
json.field "params", params.try &.as_s
|
json.field "params", params.try &.as_s
|
||||||
json.field "pageType", pageType
|
json.field "pageType", pageType
|
||||||
end
|
end
|
||||||
|
@ -205,8 +205,6 @@ module Invidious::Routes::Channels
|
|||||||
thin_mode = env.params.query["thin_mode"]? || prefs.thin_mode
|
thin_mode = env.params.query["thin_mode"]? || prefs.thin_mode
|
||||||
thin_mode = thin_mode == "true"
|
thin_mode = thin_mode == "true"
|
||||||
|
|
||||||
client_config = YoutubeAPI::ClientConfig.new(region: region)
|
|
||||||
|
|
||||||
if !ucid.nil?
|
if !ucid.nil?
|
||||||
ucid = ucid.to_s
|
ucid = ucid.to_s
|
||||||
post_response = fetch_channel_community_post(ucid, id, locale, "json", thin_mode)
|
post_response = fetch_channel_community_post(ucid, id, locale, "json", thin_mode)
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
"comments": ["youtube"]
|
"comments": ["youtube"]
|
||||||
},
|
},
|
||||||
"preferences" => prefs,
|
"preferences" => prefs,
|
||||||
"base_url" => "/api/v1/post/" + id + "/comments",
|
"base_url" => "/api/v1/post/#{URI.encode_www_form(id)}/comments",
|
||||||
"ucid" => ucid
|
"ucid" => ucid
|
||||||
}.to_pretty_json
|
}.to_pretty_json
|
||||||
%>
|
%>
|
||||||
|
Loading…
Reference in New Issue
Block a user