remove PG_DB & action parameter + allow force region

This commit is contained in:
Emilien Devos 2021-06-30 12:17:37 +02:00 committed by Samantaz Fox
parent d3c9607adb
commit 8452a4cd66
No known key found for this signature in database
GPG Key ID: F42821059186176E
3 changed files with 8 additions and 10 deletions

View File

@ -2066,9 +2066,6 @@ get "/api/v1/comments/:id" do |env|
format = env.params.query["format"]? format = env.params.query["format"]?
format ||= "json" format ||= "json"
action = env.params.query["action"]?
action ||= "action_get_comments"
continuation = env.params.query["continuation"]? continuation = env.params.query["continuation"]?
sort_by = env.params.query["sort_by"]?.try &.downcase sort_by = env.params.query["sort_by"]?.try &.downcase
@ -2076,7 +2073,7 @@ get "/api/v1/comments/:id" do |env|
sort_by ||= "top" sort_by ||= "top"
begin begin
comments = fetch_youtube_comments(id, PG_DB, continuation, format, locale, thin_mode, region, sort_by: sort_by, action: action) comments = fetch_youtube_comments(id, continuation, format, locale, thin_mode, region, sort_by: sort_by)
rescue ex rescue ex
next error_json(500, ex) next error_json(500, ex)
end end

View File

@ -56,7 +56,7 @@ class RedditListing
property modhash : String property modhash : String
end end
def fetch_youtube_comments(id, db, cursor, format, locale, thin_mode, region, sort_by = "top", action = "action_get_comments") def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_by = "top")
case cursor case cursor
when nil, "" when nil, ""
ctoken = produce_comment_continuation(id, cursor: "", sort_by: sort_by) ctoken = produce_comment_continuation(id, cursor: "", sort_by: sort_by)
@ -68,7 +68,8 @@ def fetch_youtube_comments(id, db, cursor, format, locale, thin_mode, region, so
ctoken = cursor ctoken = cursor
end end
response = YoutubeAPI.next(continuation: ctoken) client_config = YoutubeAPI::ClientConfig.new(region: region)
response = YoutubeAPI.next(continuation: ctoken, client_config: client_config)
if !response["continuationContents"]? if !response["continuationContents"]?
raise InfoException.new("Could not fetch comments") raise InfoException.new("Could not fetch comments")
@ -209,7 +210,7 @@ def fetch_youtube_comments(id, db, cursor, format, locale, thin_mode, region, so
if format == "html" if format == "html"
response = JSON.parse(response) response = JSON.parse(response)
content_html = template_youtube_comments(response, locale, thin_mode, action == "action_get_comment_replies") content_html = template_youtube_comments(response, locale, thin_mode)
response = JSON.build do |json| response = JSON.build do |json|
json.object do json.object do

View File

@ -92,7 +92,7 @@ class Invidious::Routes::Watch < Invidious::Routes::BaseRoute
if source == "youtube" if source == "youtube"
begin begin
comment_html = JSON.parse(fetch_youtube_comments(id, PG_DB, nil, "html", locale, preferences.thin_mode, region))["contentHtml"] comment_html = JSON.parse(fetch_youtube_comments(id, nil, "html", locale, preferences.thin_mode, region))["contentHtml"]
rescue ex rescue ex
if preferences.comments[1] == "reddit" if preferences.comments[1] == "reddit"
comments, reddit_thread = fetch_reddit_comments(id) comments, reddit_thread = fetch_reddit_comments(id)
@ -111,12 +111,12 @@ class Invidious::Routes::Watch < Invidious::Routes::BaseRoute
comment_html = replace_links(comment_html) comment_html = replace_links(comment_html)
rescue ex rescue ex
if preferences.comments[1] == "youtube" if preferences.comments[1] == "youtube"
comment_html = JSON.parse(fetch_youtube_comments(id, PG_DB, nil, "html", locale, preferences.thin_mode, region))["contentHtml"] comment_html = JSON.parse(fetch_youtube_comments(id, nil, "html", locale, preferences.thin_mode, region))["contentHtml"]
end end
end end
end end
else else
comment_html = JSON.parse(fetch_youtube_comments(id, PG_DB, nil, "html", locale, preferences.thin_mode, region))["contentHtml"] comment_html = JSON.parse(fetch_youtube_comments(id, nil, "html", locale, preferences.thin_mode, region))["contentHtml"]
end end
comment_html ||= "" comment_html ||= ""