Skip to content

Commit 1d25c55

Browse files
authored
Merge pull request #2859 from jonas-w/verified-badge
Youtube verification badge
2 parents 6376e78 + ec3e67e commit 1d25c55

File tree

11 files changed

+77
-26
lines changed

11 files changed

+77
-26
lines changed

src/invidious/channels/about.cr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ record AboutChannel,
1212
joined : Time,
1313
is_family_friendly : Bool,
1414
allowed_regions : Array(String),
15-
tabs : Array(String)
15+
tabs : Array(String),
16+
verified : Bool
1617

1718
record AboutRelatedChannel,
1819
ucid : String,
@@ -70,6 +71,9 @@ def get_about_info(ucid, locale) : AboutChannel
7071
# if banner.includes? "channels/c4/default_banner"
7172
# banner = nil
7273
# end
74+
# author_verified_badges = initdata["header"]?.try &.["c4TabbedHeaderRenderer"]?.try &.["badges"]?
75+
author_verified_badge = initdata["header"].dig?("c4TabbedHeaderRenderer", "badges", 0, "metadataBadgeRenderer", "tooltip")
76+
author_verified = (author_verified_badge && author_verified_badge == "Verified")
7377

7478
description = initdata["metadata"]["channelMetadataRenderer"]?.try &.["description"]?.try &.as_s? || ""
7579
description_html = HTML.escape(description)
@@ -128,6 +132,7 @@ def get_about_info(ucid, locale) : AboutChannel
128132
is_family_friendly: is_family_friendly,
129133
allowed_regions: allowed_regions,
130134
tabs: tabs,
135+
verified: author_verified || false,
131136
)
132137
end
133138

src/invidious/comments.cr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
146146
content_html = node_comment["contentText"]?.try { |t| parse_content(t) } || ""
147147
author = node_comment["authorText"]?.try &.["simpleText"]? || ""
148148

149+
json.field "verified", (node_comment["authorCommentBadge"]? != nil)
150+
149151
json.field "author", author
150152
json.field "authorThumbnails" do
151153
json.array do
@@ -329,7 +331,11 @@ def template_youtube_comments(comments, locale, thin_mode, is_replies = false)
329331
end
330332

331333
author_name = HTML.escape(child["author"].as_s)
332-
334+
if child["verified"]?.try &.as_bool && child["authorIsChannelOwner"]?.try &.as_bool
335+
author_name += "&nbsp;<i class=\"icon ion ion-md-checkmark-circle\"></i>"
336+
elsif child["verified"]?.try &.as_bool
337+
author_name += "&nbsp;<i class=\"icon ion ion-md-checkmark\"></i>"
338+
end
333339
html << <<-END_HTML
334340
<div class="pure-g" style="width:100%">
335341
<div class="channel-profile pure-u-4-24 pure-u-md-2-24">

src/invidious/helpers/serialized_yt_data.cr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct SearchVideo
1212
property live_now : Bool
1313
property premium : Bool
1414
property premiere_timestamp : Time?
15+
property author_verified : Bool
1516

1617
def to_xml(auto_generated, query_params, xml : XML::Builder)
1718
query_params["v"] = self.id
@@ -129,6 +130,7 @@ struct SearchPlaylist
129130
property video_count : Int32
130131
property videos : Array(SearchPlaylistVideo)
131132
property thumbnail : String?
133+
property author_verified : Bool
132134

133135
def to_json(locale : String?, json : JSON::Builder)
134136
json.object do
@@ -141,6 +143,8 @@ struct SearchPlaylist
141143
json.field "authorId", self.ucid
142144
json.field "authorUrl", "/channel/#{self.ucid}"
143145

146+
json.field "authorVerified", self.author_verified
147+
144148
json.field "videoCount", self.video_count
145149
json.field "videos" do
146150
json.array do
@@ -182,14 +186,15 @@ struct SearchChannel
182186
property video_count : Int32
183187
property description_html : String
184188
property auto_generated : Bool
189+
property author_verified : Bool
185190

186191
def to_json(locale : String?, json : JSON::Builder)
187192
json.object do
188193
json.field "type", "channel"
189194
json.field "author", self.author
190195
json.field "authorId", self.ucid
191196
json.field "authorUrl", "/channel/#{self.ucid}"
192-
197+
json.field "authorVerified", self.author_verified
193198
json.field "authorThumbnails" do
194199
json.array do
195200
qualities = {32, 48, 76, 100, 176, 512}

src/invidious/routes/feeds.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ module Invidious::Routes::Feeds
182182
paid: false,
183183
premium: false,
184184
premiere_timestamp: nil,
185+
author_verified: false, # ¯\_(ツ)_/¯
185186
})
186187
end
187188

src/invidious/videos.cr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,10 @@ struct Video
609609
info["authorThumbnail"]?.try &.as_s || ""
610610
end
611611

612+
def author_verified : Bool
613+
info["authorVerified"].try &.as_bool || false
614+
end
615+
612616
def sub_count_text : String
613617
info["subCountText"]?.try &.as_s || "-"
614618
end
@@ -860,6 +864,12 @@ def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)?
860864
.try &.dig?("runs", 0)
861865

862866
author = channel_info.try &.dig?("text")
867+
author_verified_badge = related["ownerBadges"]?.try do |badges_array|
868+
badges_array.as_a.find(&.dig("metadataBadgeRenderer", "tooltip").as_s.== "Verified")
869+
end
870+
871+
author_verified = (author_verified_badge && author_verified_badge.size > 0).to_s
872+
863873
ucid = channel_info.try { |ci| HelperExtractors.get_browse_id(ci) }
864874

865875
# "4,088,033 views", only available on compact renderer
@@ -883,6 +893,7 @@ def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)?
883893
"length_seconds" => JSON::Any.new(length || "0"),
884894
"view_count" => JSON::Any.new(view_count || "0"),
885895
"short_view_count" => JSON::Any.new(short_view_count || "0"),
896+
"author_verified" => JSON::Any.new(author_verified),
886897
}
887898
end
888899

@@ -1077,6 +1088,9 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_
10771088
author_info = video_secondary_renderer.try &.dig?("owner", "videoOwnerRenderer")
10781089
author_thumbnail = author_info.try &.dig?("thumbnail", "thumbnails", 0, "url")
10791090

1091+
author_verified_badge = author_info.try &.dig?("badges", 0, "metadataBadgeRenderer", "tooltip")
1092+
params["authorVerified"] = JSON::Any.new((author_verified_badge && author_verified_badge == "Verified"))
1093+
10801094
params["authorThumbnail"] = JSON::Any.new(author_thumbnail.try &.as_s || "")
10811095

10821096
params["subCountText"] = JSON::Any.new(author_info.try &.["subscriberCountText"]?

src/invidious/views/channel.ecr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<div class="pure-u-2-3">
2121
<div class="channel-profile">
2222
<img src="/ggpht<%= URI.parse(channel.author_thumbnail).request_target %>">
23-
<span><%= author %></span>
23+
<span><%= author %></span><% if !channel.verified.nil? && channel.verified %>&nbsp;<i class="icon ion ion-md-checkmark-circle"></i><% end %>
2424
</div>
2525
</div>
2626
<div class="pure-u-1-3">

src/invidious/views/community.ecr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div class="pure-u-2-3">
2020
<div class="channel-profile">
2121
<img src="/ggpht<%= URI.parse(channel.author_thumbnail).request_target %>">
22-
<span><%= author %></span>
22+
<span><%= author %></span><% if !channel.verified.nil? && channel.verified %>&nbsp;<i class="icon ion ion-md-checkmark-circle"></i><% end %>
2323
</div>
2424
</div>
2525
<div class="pure-u-1-3" style="text-align:right">

src/invidious/views/components/item.ecr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<img loading="lazy" style="width:56.25%" src="/ggpht<%= URI.parse(item.author_thumbnail).request_target.gsub(/=s\d+/, "=s176") %>"/>
99
</center>
1010
<% end %>
11-
<p dir="auto"><%= HTML.escape(item.author) %></p>
11+
<p dir="auto"><%= HTML.escape(item.author) %><% if !item.author_verified.nil? && item.author_verified %>&nbsp;<i class="icon ion ion-md-checkmark-circle"></i><% end %></p>
1212
</a>
1313
<p><%= translate_count(locale, "generic_subscribers_count", item.subscriber_count, NumberFormatting::Separator) %></p>
1414
<% if !item.auto_generated %><p><%= translate_count(locale, "generic_videos_count", item.video_count, NumberFormatting::Separator) %></p><% end %>
@@ -30,7 +30,7 @@
3030
<p dir="auto"><%= HTML.escape(item.title) %></p>
3131
</a>
3232
<a href="/channel/<%= item.ucid %>">
33-
<p dir="auto"><b><%= HTML.escape(item.author) %></b></p>
33+
<p dir="auto"><b><%= HTML.escape(item.author) %><% if !item.is_a?(InvidiousPlaylist) && !item.author_verified.nil? && item.author_verified %>&nbsp;<i class="icon ion ion-md-checkmark-circle"></i><% end %></b></p>
3434
</a>
3535
<% when MixVideo %>
3636
<a href="/watch?v=<%= item.id %>&list=<%= item.rdid %>">
@@ -142,7 +142,7 @@
142142

143143
<div class="video-card-row flexible">
144144
<div class="flex-left"><a href="/channel/<%= item.ucid %>">
145-
<p class="channel-name" dir="auto"><%= HTML.escape(item.author) %></p>
145+
<p class="channel-name" dir="auto"><%= HTML.escape(item.author) %><% if !item.is_a?(ChannelVideo) && !item.author_verified.nil? && item.author_verified %>&nbsp;<i class="icon ion ion-md-checkmark-circle"></i><% end %></p>
146146
</a></div>
147147

148148
<% endpoint_params = "?v=#{item.id}" %>

src/invidious/views/playlists.ecr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div class="pure-u-2-3">
2020
<div class="channel-profile">
2121
<img src="/ggpht<%= URI.parse(channel.author_thumbnail).request_target %>">
22-
<span><%= author %></span>
22+
<span><%= author %></span><% if !channel.verified.nil? && channel.verified %>&nbsp;<i class="icon ion ion-md-checkmark-circle"></i><% end %>
2323
</div>
2424
</div>
2525
<div class="pure-u-1-3" style="text-align:right">

src/invidious/views/watch.ecr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ we're going to need to do it here in order to allow for translations.
207207
<% if !video.author_thumbnail.empty? %>
208208
<img src="/ggpht<%= URI.parse(video.author_thumbnail).request_target %>">
209209
<% end %>
210-
<span id="channel-name"><%= author %></span>
210+
<span id="channel-name"><%= author %><% if !video.author_verified.nil? && video.author_verified %>&nbsp;<i class="icon ion ion-md-checkmark-circle"></i><% end %></span>
211211
</div>
212212
</a>
213213
@@ -281,9 +281,9 @@ we're going to need to do it here in order to allow for translations.
281281
<h5 class="pure-g">
282282
<div class="pure-u-14-24">
283283
<% if rv["ucid"]? %>
284-
<b style="width:100%"><a href="/channel/<%= rv["ucid"] %>"><%= rv["author"]? %></a></b>
284+
<b style="width:100%"><a href="/channel/<%= rv["ucid"] %>"><%= rv["author"]? %><% if rv["author_verified"]? == "true" %>&nbsp;<i class="icon ion ion-md-checkmark-circle"></i><% end %></a></b>
285285
<% else %>
286-
<b style="width:100%"><%= rv["author"]? %></b>
286+
<b style="width:100%"><%= rv["author"]? %><% if rv["author_verified"]? == "true" %>&nbsp;<i class="icon ion ion-md-checkmark-circle"></i><% end %></b>
287287
<% end %>
288288
</div>
289289

0 commit comments

Comments
 (0)