summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Zhao <azhao12345@users.noreply.github.com>2021-03-18 01:23:32 -0400
committerAndrew Zhao <azhao12345@users.noreply.github.com>2021-03-20 00:43:12 -0400
commit89fd35e02d0e8de585c3f5d619fb45986ac1173a (patch)
tree24b869c1478146efb5c08ed40f34270ac6fcbc89 /src
parent3286328de4cd64b48265b42333bfa67346b7a0b9 (diff)
downloadinvidious-89fd35e02d0e8de585c3f5d619fb45986ac1173a.tar.gz
invidious-89fd35e02d0e8de585c3f5d619fb45986ac1173a.tar.bz2
invidious-89fd35e02d0e8de585c3f5d619fb45986ac1173a.zip
fix comment replies
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr5
-rw-r--r--src/invidious/comments.cr17
2 files changed, 15 insertions, 7 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 89d99ecc..8d579f92 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -2054,6 +2054,9 @@ get "/api/v1/comments/:id" do |env|
format = env.params.query["format"]?
format ||= "json"
+ action = env.params.query["action"]?
+ action ||= "action_get_comments"
+
continuation = env.params.query["continuation"]?
sort_by = env.params.query["sort_by"]?.try &.downcase
@@ -2061,7 +2064,7 @@ get "/api/v1/comments/:id" do |env|
sort_by ||= "top"
begin
- comments = fetch_youtube_comments(id, PG_DB, continuation, format, locale, thin_mode, region, sort_by: sort_by)
+ comments = fetch_youtube_comments(id, PG_DB, continuation, format, locale, thin_mode, region, sort_by: sort_by, action: action)
rescue ex
next error_json(500, ex)
end
diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr
index 20e64a08..e7e87203 100644
--- a/src/invidious/comments.cr
+++ b/src/invidious/comments.cr
@@ -56,7 +56,7 @@ class RedditListing
property modhash : String
end
-def fetch_youtube_comments(id, db, cursor, format, locale, thin_mode, region, sort_by = "top")
+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
@@ -88,9 +88,14 @@ def fetch_youtube_comments(id, db, cursor, format, locale, thin_mode, region, so
"cookie" => video.cookie,
}
- response = YT_POOL.client(region, &.post("/comment_service_ajax?action_get_comments=1&hl=en&gl=US&pbj=1", headers, form: post_req))
+ 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")
end
@@ -228,7 +233,7 @@ def fetch_youtube_comments(id, db, cursor, format, locale, thin_mode, region, so
if format == "html"
response = JSON.parse(response)
- content_html = template_youtube_comments(response, locale, thin_mode)
+ content_html = template_youtube_comments(response, locale, thin_mode, action == "action_get_comment_replies")
response = JSON.build do |json|
json.object do
@@ -281,7 +286,7 @@ def fetch_reddit_comments(id, sort_by = "confidence")
return comments, thread
end
-def template_youtube_comments(comments, locale, thin_mode)
+def template_youtube_comments(comments, locale, thin_mode, is_replies = false)
String.build do |html|
root = comments["comments"].as_a
root.each do |child|
@@ -292,7 +297,7 @@ def template_youtube_comments(comments, locale, thin_mode)
<div class="pure-u-23-24">
<p>
<a href="javascript:void(0)" data-continuation="#{child["replies"]["continuation"]}"
- data-onclick="get_youtube_replies">#{translate(locale, "View `x` replies", number_with_separator(child["replies"]["replyCount"]))}</a>
+ data-onclick="get_youtube_replies" data-load-replies>#{translate(locale, "View `x` replies", number_with_separator(child["replies"]["replyCount"]))}</a>
</p>
</div>
</div>
@@ -412,7 +417,7 @@ def template_youtube_comments(comments, locale, thin_mode)
<div class="pure-u-1">
<p>
<a href="javascript:void(0)" data-continuation="#{comments["continuation"]}"
- data-onclick="get_youtube_replies" data-load-more>#{translate(locale, "Load more")}</a>
+ data-onclick="get_youtube_replies" data-load-more #{"data-load-replies" if is_replies}>#{translate(locale, "Load more")}</a>
</p>
</div>
</div>