mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-13 08:08:31 +00:00
use the new youtube api for comments
This commit is contained in:
parent
5b020e81ca
commit
f124897008
@ -58,7 +58,6 @@ end
|
||||
|
||||
def fetch_youtube_comments(id, db, cursor, format, locale, thin_mode, region, sort_by = "top", action = "action_get_comments")
|
||||
video = get_video(id, db, region: region)
|
||||
session_token = video.session_token
|
||||
|
||||
case cursor
|
||||
when nil, ""
|
||||
@ -71,36 +70,13 @@ def fetch_youtube_comments(id, db, cursor, format, locale, thin_mode, region, so
|
||||
ctoken = cursor
|
||||
end
|
||||
|
||||
if !session_token
|
||||
if format == "json"
|
||||
return {"comments" => [] of String}.to_json
|
||||
else
|
||||
return {"contentHtml" => "", "commentCount" => 0}.to_json
|
||||
end
|
||||
end
|
||||
response = YoutubeAPI.next(continuation: ctoken)
|
||||
|
||||
post_req = {
|
||||
page_token: ctoken,
|
||||
session_token: session_token,
|
||||
}
|
||||
|
||||
headers = HTTP::Headers{
|
||||
"cookie" => video.cookie,
|
||||
}
|
||||
|
||||
response = YT_POOL.client(region, &.post("/comment_service_ajax?#{action}=1&hl=en&gl=US&pbj=1", headers, form: post_req))
|
||||
response = JSON.parse(response.body)
|
||||
|
||||
# For some reason youtube puts it in an array for comment_replies but otherwise it's the same
|
||||
if action == "action_get_comment_replies"
|
||||
response = response[1]
|
||||
end
|
||||
|
||||
if !response["response"]["continuationContents"]?
|
||||
if !response["continuationContents"]?
|
||||
raise InfoException.new("Could not fetch comments")
|
||||
end
|
||||
|
||||
response = response["response"]["continuationContents"]
|
||||
response = response["continuationContents"]
|
||||
if response["commentRepliesContinuation"]?
|
||||
body = response["commentRepliesContinuation"]
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user