mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-14 08:38:30 +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")
|
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)
|
video = get_video(id, db, region: region)
|
||||||
session_token = video.session_token
|
|
||||||
|
|
||||||
case cursor
|
case cursor
|
||||||
when nil, ""
|
when nil, ""
|
||||||
@ -71,36 +70,13 @@ def fetch_youtube_comments(id, db, cursor, format, locale, thin_mode, region, so
|
|||||||
ctoken = cursor
|
ctoken = cursor
|
||||||
end
|
end
|
||||||
|
|
||||||
if !session_token
|
response = YoutubeAPI.next(continuation: ctoken)
|
||||||
if format == "json"
|
|
||||||
return {"comments" => [] of String}.to_json
|
|
||||||
else
|
|
||||||
return {"contentHtml" => "", "commentCount" => 0}.to_json
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
post_req = {
|
if !response["continuationContents"]?
|
||||||
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"]?
|
|
||||||
raise InfoException.new("Could not fetch comments")
|
raise InfoException.new("Could not fetch comments")
|
||||||
end
|
end
|
||||||
|
|
||||||
response = response["response"]["continuationContents"]
|
response = response["continuationContents"]
|
||||||
if response["commentRepliesContinuation"]?
|
if response["commentRepliesContinuation"]?
|
||||||
body = response["commentRepliesContinuation"]
|
body = response["commentRepliesContinuation"]
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user