mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-13 16:18:29 +00:00
support new comments data with onResponseReceivedEndpoints
This commit is contained in:
parent
8452a4cd66
commit
80f7b11d76
@ -71,18 +71,38 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
|
|||||||
client_config = YoutubeAPI::ClientConfig.new(region: region)
|
client_config = YoutubeAPI::ClientConfig.new(region: region)
|
||||||
response = YoutubeAPI.next(continuation: ctoken, client_config: client_config)
|
response = YoutubeAPI.next(continuation: ctoken, client_config: client_config)
|
||||||
|
|
||||||
if !response["continuationContents"]?
|
if response["continuationContents"]?
|
||||||
|
response = response["continuationContents"]
|
||||||
|
if response["commentRepliesContinuation"]?
|
||||||
|
body = response["commentRepliesContinuation"]
|
||||||
|
else
|
||||||
|
body = response["itemSectionContinuation"]
|
||||||
|
end
|
||||||
|
contents = body["contents"]?
|
||||||
|
header = body["header"]?
|
||||||
|
if body["continuations"]?
|
||||||
|
moreRepliesContinuation = body["continuations"][0]["nextContinuationData"]["continuation"].as_s
|
||||||
|
end
|
||||||
|
elsif response["onResponseReceivedEndpoints"]?
|
||||||
|
onResponseReceivedEndpoints = response["onResponseReceivedEndpoints"]
|
||||||
|
onResponseReceivedEndpoints.as_a.each do |item|
|
||||||
|
case item["reloadContinuationItemsCommand"]["slot"]
|
||||||
|
when "RELOAD_CONTINUATION_SLOT_HEADER"
|
||||||
|
header = item["reloadContinuationItemsCommand"]["continuationItems"][0]
|
||||||
|
when "RELOAD_CONTINUATION_SLOT_BODY"
|
||||||
|
contents = item["reloadContinuationItemsCommand"]["continuationItems"]
|
||||||
|
contents.as_a.reject! do |item|
|
||||||
|
if item["continuationItemRenderer"]?
|
||||||
|
moreRepliesContinuation = item["continuationItemRenderer"]["continuationEndpoint"]["continuationCommand"]["token"].as_s
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
raise InfoException.new("Could not fetch comments")
|
raise InfoException.new("Could not fetch comments")
|
||||||
end
|
end
|
||||||
|
|
||||||
response = response["continuationContents"]
|
|
||||||
if response["commentRepliesContinuation"]?
|
|
||||||
body = response["commentRepliesContinuation"]
|
|
||||||
else
|
|
||||||
body = response["itemSectionContinuation"]
|
|
||||||
end
|
|
||||||
|
|
||||||
contents = body["contents"]?
|
|
||||||
if !contents
|
if !contents
|
||||||
if format == "json"
|
if format == "json"
|
||||||
return {"comments" => [] of String}.to_json
|
return {"comments" => [] of String}.to_json
|
||||||
@ -93,11 +113,10 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
|
|||||||
|
|
||||||
response = JSON.build do |json|
|
response = JSON.build do |json|
|
||||||
json.object do
|
json.object do
|
||||||
if body["header"]?
|
if header
|
||||||
count_text = body["header"]["commentsHeaderRenderer"]["countText"]
|
count_text = header["commentsHeaderRenderer"]["countText"]
|
||||||
comment_count = (count_text["simpleText"]? || count_text["runs"]?.try &.[0]?.try &.["text"]?)
|
comment_count = (count_text["simpleText"]? || count_text["runs"]?.try &.[0]?.try &.["text"]?)
|
||||||
.try &.as_s.gsub(/\D/, "").to_i? || 0
|
.try &.as_s.gsub(/\D/, "").to_i? || 0
|
||||||
|
|
||||||
json.field "commentCount", comment_count
|
json.field "commentCount", comment_count
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -186,7 +205,11 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
|
|||||||
reply_count = 1
|
reply_count = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
continuation = node_replies["continuations"]?.try &.as_a[0]["nextContinuationData"]["continuation"].as_s
|
if node_replies["continuations"]?
|
||||||
|
continuation = node_replies["continuations"]?.try &.as_a[0]["nextContinuationData"]["continuation"].as_s
|
||||||
|
elsif node_replies["contents"]?
|
||||||
|
continuation = node_replies["contents"]?.try &.as_a[0]["continuationItemRenderer"]["continuationEndpoint"]["continuationCommand"]["token"].as_s
|
||||||
|
end
|
||||||
continuation ||= ""
|
continuation ||= ""
|
||||||
|
|
||||||
json.field "replies" do
|
json.field "replies" do
|
||||||
@ -201,9 +224,8 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if body["continuations"]?
|
if moreRepliesContinuation
|
||||||
continuation = body["continuations"][0]["nextContinuationData"]["continuation"].as_s
|
json.field "continuation", moreRepliesContinuation
|
||||||
json.field "continuation", continuation
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user