summaryrefslogtreecommitdiffstats
path: root/src/invidious/channels/community.cr
diff options
context:
space:
mode:
Diffstat (limited to 'src/invidious/channels/community.cr')
-rw-r--r--src/invidious/channels/community.cr82
1 files changed, 26 insertions, 56 deletions
diff --git a/src/invidious/channels/community.cr b/src/invidious/channels/community.cr
index ce34ff82..aac4bc8a 100644
--- a/src/invidious/channels/community.cr
+++ b/src/invidious/channels/community.cr
@@ -31,18 +31,16 @@ def fetch_channel_community(ucid, continuation, locale, format, thin_mode)
session_token: session_token,
}
- response = YT_POOL.client &.post("/comment_service_ajax?action_get_comments=1&ctoken=#{continuation}&continuation=#{continuation}&hl=en&gl=US", headers, form: post_req)
- body = JSON.parse(response.body)
+ body = YoutubeAPI.browse(continuation)
- body = body["response"]["continuationContents"]["itemSectionContinuation"]? ||
- body["response"]["continuationContents"]["backstageCommentsContinuation"]?
+ body = body.dig?("continuationContents", "itemSectionContinuation") ||
+ body.dig?("continuationContents", "backstageCommentsContinuation")
if !body
raise InfoException.new("Could not extract continuation.")
end
end
- continuation = body["continuations"]?.try &.[0]["nextContinuationData"]["continuation"].as_s
posts = body["contents"].as_a
if message = posts[0]["messageRenderer"]?
@@ -125,49 +123,13 @@ def fetch_channel_community(ucid, continuation, locale, format, thin_mode)
if attachment = post["backstageAttachment"]?
json.field "attachment" do
- json.object do
- case attachment.as_h
- when .has_key?("videoRenderer")
- attachment = attachment["videoRenderer"]
- json.field "type", "video"
-
- if !attachment["videoId"]?
- error_message = (attachment["title"]["simpleText"]? ||
- attachment["title"]["runs"]?.try &.[0]?.try &.["text"]?)
-
- json.field "error", error_message
- else
- video_id = attachment["videoId"].as_s
-
- video_title = attachment["title"]["simpleText"]? || attachment["title"]["runs"]?.try &.[0]?.try &.["text"]?
- json.field "title", video_title
- json.field "videoId", video_id
- json.field "videoThumbnails" do
- Invidious::JSONify::APIv1.thumbnails(json, video_id)
- end
-
- json.field "lengthSeconds", decode_length_seconds(attachment["lengthText"]["simpleText"].as_s)
-
- author_info = attachment["ownerText"]["runs"][0].as_h
-
- json.field "author", author_info["text"].as_s
- json.field "authorId", author_info["navigationEndpoint"]["browseEndpoint"]["browseId"]
- json.field "authorUrl", author_info["navigationEndpoint"]["commandMetadata"]["webCommandMetadata"]["url"]
-
- # TODO: json.field "authorThumbnails", "channelThumbnailSupportedRenderers"
- # TODO: json.field "authorVerified", "ownerBadges"
-
- published = decode_date(attachment["publishedTimeText"]["simpleText"].as_s)
-
- json.field "published", published.to_unix
- json.field "publishedText", translate(locale, "`x` ago", recode_date(published, locale))
-
- view_count = attachment["viewCountText"]?.try &.["simpleText"].as_s.gsub(/\D/, "").to_i64? || 0_i64
-
- json.field "viewCount", view_count
- json.field "viewCountText", translate_count(locale, "generic_views_count", view_count, NumberFormatting::Short)
- end
- when .has_key?("backstageImageRenderer")
+ case attachment.as_h
+ when .has_key?("videoRenderer")
+ parse_item(attachment)
+ .as(SearchVideo)
+ .to_json(locale, json)
+ when .has_key?("backstageImageRenderer")
+ json.object do
attachment = attachment["backstageImageRenderer"]
json.field "type", "image"
@@ -188,7 +150,9 @@ def fetch_channel_community(ucid, continuation, locale, format, thin_mode)
end
end
end
- when .has_key?("pollRenderer")
+ end
+ when .has_key?("pollRenderer")
+ json.object do
attachment = attachment["pollRenderer"]
json.field "type", "poll"
json.field "totalVotes", short_text_to_number(attachment["totalVotes"]["simpleText"].as_s.split(" ")[0])
@@ -221,7 +185,9 @@ def fetch_channel_community(ucid, continuation, locale, format, thin_mode)
end
end
end
- when .has_key?("postMultiImageRenderer")
+ end
+ when .has_key?("postMultiImageRenderer")
+ json.object do
attachment = attachment["postMultiImageRenderer"]
json.field "type", "multiImage"
json.field "images" do
@@ -245,7 +211,13 @@ def fetch_channel_community(ucid, continuation, locale, format, thin_mode)
end
end
end
- else
+ end
+ when .has_key?("playlistRenderer")
+ parse_item(attachment)
+ .as(SearchPlaylist)
+ .to_json(locale, json)
+ else
+ json.object do
json.field "type", "unknown"
json.field "error", "Unrecognized attachment type."
end
@@ -270,17 +242,15 @@ def fetch_channel_community(ucid, continuation, locale, format, thin_mode)
end
end
end
-
- if body["continuations"]?
- continuation = body["continuations"][0]["nextContinuationData"]["continuation"].as_s
- json.field "continuation", extract_channel_community_cursor(continuation)
+ if cont = posts.dig?(-1, "continuationItemRenderer", "continuationEndpoint", "continuationCommand", "token")
+ json.field "continuation", extract_channel_community_cursor(cont.as_s)
end
end
end
if format == "html"
response = JSON.parse(response)
- content_html = template_youtube_comments(response, locale, thin_mode)
+ content_html = IV::Frontend::Comments.template_youtube(response, locale, thin_mode)
response = JSON.build do |json|
json.object do