From 4f1cb26d96aa375825536a2c25bc34270882f2b6 Mon Sep 17 00:00:00 2001 From: syeopite Date: Wed, 7 Apr 2021 02:16:20 -0700 Subject: [PATCH] Add support for verified badges on comments --- src/invidious.cr | 4 ++-- src/invidious/channels.cr | 10 +++++----- src/invidious/comments.cr | 4 ++++ src/invidious/helpers/helpers.cr | 32 ++++++++++++++++---------------- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 44300c0d..d4af13dc 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1302,7 +1302,7 @@ get "/feed/channel/:ucid" do |env| title: title, id: video_id, author: author, - author_verified: false, + author_verified: false, ucid: ucid, published: published, views: views, @@ -1550,7 +1550,7 @@ post "/feed/webhook/:token" do |env| updated: updated, ucid: video.ucid, author: author, - author_verified: false, + author_verified: false, length_seconds: video.length_seconds, live_now: video.live_now, premiere_timestamp: video.premiere_timestamp, diff --git a/src/invidious/channels.cr b/src/invidious/channels.cr index 38d93b75..9ba3ac96 100644 --- a/src/invidious/channels.cr +++ b/src/invidious/channels.cr @@ -126,7 +126,7 @@ struct AboutChannel property auto_generated : Bool property author_url : String property author_thumbnail : String - property author_verified : Bool + property author_verified : Bool property banner : String? property description_html : String property paid : Bool @@ -276,7 +276,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil) updated: Time.utc, ucid: ucid, author: author, - author_verified: false, + author_verified: false, length_seconds: length_seconds, live_now: live_now, premiere_timestamp: premiere_timestamp, @@ -285,7 +285,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil) # I don't understand enough about the database to do anything. Thus: reduced_video_list = {video_id, title, published, Time.utc, ucid, author, - length_seconds, live_now, premiere_timestamp, views} + length_seconds, live_now, premiere_timestamp, views} LOGGER.trace("fetch_channel: #{ucid} : video #{video_id} : Updating or inserting video") @@ -324,7 +324,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil) updated: Time.utc, ucid: video.ucid, author: video.author, - author_verified: video.author_verified, + author_verified: video.author_verified, length_seconds: video.length_seconds, live_now: video.live_now, premiere_timestamp: video.premiere_timestamp, @@ -925,7 +925,7 @@ def get_about_info(ucid, locale) auto_generated: auto_generated, author_url: author_url, author_thumbnail: author_thumbnail, - author_verified: author_verified, + author_verified: author_verified, banner: banner, description_html: description_html, paid: paid, diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index 5d72503e..38aa5847 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -148,8 +148,10 @@ def fetch_youtube_comments(id, db, cursor, format, locale, thin_mode, region, so content_html = node_comment["contentText"]?.try { |t| parse_content(t) } || "" author = node_comment["authorText"]?.try &.["simpleText"]? || "" + author_verified = node_comment["authorCommentBadge"]?.try &.["authorCommentBadgeRenderer"]["iconTooltip"].to_s == "Verified" ? true : false || false json.field "author", author + json.field "author_verified", author_verified json.field "authorThumbnails" do json.array do node_comment["authorThumbnail"]["thumbnails"].as_a.each do |thumbnail| @@ -319,7 +321,9 @@ def template_youtube_comments(comments, locale, thin_mode, is_replies = false)

#{child["author"]} + #{child["author_verified"]? == true ? "" : ""} +

#{child["contentHtml"]}

END_HTML diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index f97559ce..4868176f 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -299,7 +299,7 @@ def extract_item(item : JSON::Any, author_fallback : String? = nil, author_id_fa title: title, id: video_id, author: author, - author_verified: author_verified, + author_verified: author_verified, ucid: author_id, published: published, views: view_count, @@ -326,7 +326,7 @@ def extract_item(item : JSON::Any, author_fallback : String? = nil, author_id_fa SearchChannel.new({ author: author, - author_verified: author_verified, + author_verified: author_verified, ucid: author_id, author_thumbnail: author_thumbnail, subscriber_count: subscriber_count, @@ -342,14 +342,14 @@ def extract_item(item : JSON::Any, author_fallback : String? = nil, author_id_fa playlist_thumbnail = i["thumbnail"]["thumbnails"][0]?.try &.["url"]?.try &.as_s || "" SearchPlaylist.new({ - title: title, - id: plid, - author: author_fallback || "", + title: title, + id: plid, + author: author_fallback || "", author_verified: false, - ucid: author_id_fallback || "", - video_count: video_count, - videos: [] of SearchPlaylistVideo, - thumbnail: playlist_thumbnail, + ucid: author_id_fallback || "", + video_count: video_count, + videos: [] of SearchPlaylistVideo, + thumbnail: playlist_thumbnail, }) elsif i = item["playlistRenderer"]? title = i["title"]["simpleText"]?.try &.as_s || "" @@ -378,14 +378,14 @@ def extract_item(item : JSON::Any, author_fallback : String? = nil, author_id_fa # TODO: i["publishedTimeText"]? SearchPlaylist.new({ - title: title, - id: plid, - author: author, + title: title, + id: plid, + author: author, author_verified: author_verified, - ucid: author_id, - video_count: video_count, - videos: videos, - thumbnail: playlist_thumbnail, + ucid: author_id, + video_count: video_count, + videos: videos, + thumbnail: playlist_thumbnail, }) elsif i = item["radioRenderer"]? # Mix # TODO