Skip to content

Commit 00df3e2

Browse files
committed
Refactored code and added badges to Search but many dummies because of the way components/item works
1 parent a2578ac commit 00df3e2

File tree

10 files changed

+69
-30
lines changed

10 files changed

+69
-30
lines changed

src/invidious/channels/about.cr

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_about_info(ucid, locale) : AboutChannel
4242
if !initdata.has_key?("metadata")
4343
auto_generated = true
4444
end
45-
verified = false
45+
4646
if auto_generated
4747
author = initdata["header"]["interactiveTabbedHeaderRenderer"]["title"]["simpleText"].as_s
4848
author_url = initdata["microformat"]["microformatDataRenderer"]["urlCanonical"].as_s
@@ -71,10 +71,9 @@ def get_about_info(ucid, locale) : AboutChannel
7171
# if banner.includes? "channels/c4/default_banner"
7272
# banner = nil
7373
# end
74-
badges = initdata["header"]["c4TabbedHeaderRenderer"]?.try &.["badges"]?
75-
if !badges.nil?
76-
verified = true
77-
end
74+
author_verified_badges = initdata["header"]?.try &.["c4TabbedHeaderRenderer"]?.try &.["badges"]?
75+
76+
author_verified = (author_verified_badges && author_verified_badges.size > 0)
7877
description = initdata["metadata"]["channelMetadataRenderer"]?.try &.["description"]?.try &.as_s? || ""
7978
description_html = HTML.escape(description)
8079

@@ -132,7 +131,7 @@ def get_about_info(ucid, locale) : AboutChannel
132131
is_family_friendly: is_family_friendly,
133132
allowed_regions: allowed_regions,
134133
tabs: tabs,
135-
verified: verified,
134+
verified: author_verified || false,
136135
)
137136
end
138137

src/invidious/channels/channels.cr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct ChannelVideo
2121
property live_now : Bool = false
2222
property premiere_timestamp : Time? = nil
2323
property views : Int64? = nil
24+
property author_verified : Bool #TODO currently a dummy
2425

2526
def to_json(locale, json : JSON::Builder)
2627
json.object do
@@ -218,6 +219,7 @@ def fetch_channel(ucid, pull_all_videos : Bool)
218219
live_now: live_now,
219220
premiere_timestamp: premiere_timestamp,
220221
views: views,
222+
author_verified: false, #TODO dummy for components/item.ecr
221223
})
222224

223225
LOGGER.trace("fetch_channel: #{ucid} : video #{video_id} : Updating or inserting video")
@@ -255,6 +257,7 @@ def fetch_channel(ucid, pull_all_videos : Bool)
255257
live_now: video.live_now,
256258
premiere_timestamp: video.premiere_timestamp,
257259
views: video.views,
260+
author_verified: false, #TODO dummy for components/item.ecr
258261
}) }
259262

260263
videos.each do |video|

src/invidious/comments.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
144144

145145
content_html = node_comment["contentText"]?.try { |t| parse_content(t) } || ""
146146
author = node_comment["authorText"]?.try &.["simpleText"]? || ""
147-
verified = node_comment["authorCommentBadge"]? != nil
148-
json.field "verified", verified
147+
verified = (node_comment["authorCommentBadge"]? != nil)
148+
json.field "verified", (verified || false)
149149
json.field "author", author
150150
json.field "authorThumbnails" do
151151
json.array do
@@ -329,7 +329,7 @@ def template_youtube_comments(comments, locale, thin_mode, is_replies = false)
329329
end
330330

331331
author_name = HTML.escape(child["author"].as_s)
332-
if child["verified"].as_bool
332+
if child["verified"]?.try &.as_bool
333333
author_name += "<i class=\"icon ion ion-md-checkmark-circle\"></i>"
334334
end
335335
html << <<-END_HTML

src/invidious/helpers/serialized_yt_data.cr

Lines changed: 5 additions & 2 deletions
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
@@ -140,7 +142,7 @@ struct SearchPlaylist
140142
json.field "author", self.author
141143
json.field "authorId", self.ucid
142144
json.field "authorUrl", "/channel/#{self.ucid}"
143-
145+
json.field "authorVerified", self.author_verified
144146
json.field "videoCount", self.video_count
145147
json.field "videos" do
146148
json.array do
@@ -182,14 +184,15 @@ struct SearchChannel
182184
property video_count : Int32
183185
property description_html : String
184186
property auto_generated : Bool
187+
property author_verified : Bool
185188

186189
def to_json(locale : String?, json : JSON::Builder)
187190
json.object do
188191
json.field "type", "channel"
189192
json.field "author", self.author
190193
json.field "authorId", self.ucid
191194
json.field "authorUrl", "/channel/#{self.ucid}"
192-
195+
json.field "authorVerified", self.author_verified
193196
json.field "authorThumbnails" do
194197
json.array do
195198
qualities = {32, 48, 76, 100, 176, 512}

src/invidious/mixes.cr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ struct MixVideo
88
property length_seconds : Int32
99
property index : Int32
1010
property rdid : String
11+
12+
def author_verified
13+
false #TODO dummy
14+
end
1115
end
1216

1317
struct Mix

src/invidious/playlists.cr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ struct InvidiousPlaylist
234234
0_i64
235235
end
236236

237+
def author_verified
238+
false # TODO dummy for components/item.ecr
239+
end
240+
237241
def description_html
238242
HTML.escape(self.description)
239243
end
@@ -252,6 +256,7 @@ def create_playlist(title, privacy, user)
252256
updated: Time.utc,
253257
privacy: privacy,
254258
index: [] of Int64,
259+
author_verified: false, # TODO dummy for components/item.ecr
255260
})
256261

257262
Invidious::Database::Playlists.insert(playlist)
@@ -270,6 +275,7 @@ def subscribe_playlist(user, playlist)
270275
updated: playlist.updated,
271276
privacy: PlaylistPrivacy::Private,
272277
index: [] of Int64,
278+
author_verified: false, # TODO dummy for components/item.ecr
273279
})
274280

275281
Invidious::Database::Playlists.insert(playlist)

src/invidious/routes/feeds.cr

Lines changed: 2 additions & 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, #TODO real value
185186
})
186187
end
187188

@@ -414,6 +415,7 @@ module Invidious::Routes::Feeds
414415
live_now: video.live_now,
415416
premiere_timestamp: video.premiere_timestamp,
416417
views: video.views,
418+
author_verified: false, #TODO dummy for components/item.ecr
417419
})
418420

419421
was_insert = Invidious::Database::ChannelVideos.insert(video, with_premiere_timestamp: true)

src/invidious/videos.cr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,9 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_
10471047

10481048
author_info = video_secondary_renderer.try &.dig?("owner", "videoOwnerRenderer")
10491049
author_thumbnail = author_info.try &.dig?("thumbnail", "thumbnails", 0, "url")
1050-
params["authorVerified"] = JSON::Any.new(author_info.try &.["badges"]? != nil)
1050+
author_verified_badge = author_info.try &.["badges"]?
1051+
1052+
params["authorVerified"] = JSON::Any.new((author_verified_badge && author_verified_badge.size > 0) || false)
10511053
params["authorThumbnail"] = JSON::Any.new(author_thumbnail.try &.as_s || "")
10521054

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

src/invidious/views/components/item.ecr

Lines changed: 4 additions & 4 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 %><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.author_verified.nil? && item.author_verified %><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 %>">
@@ -45,7 +45,7 @@
4545
<p dir="auto"><%= HTML.escape(item.title) %></p>
4646
</a>
4747
<a href="/channel/<%= item.ucid %>">
48-
<p dir="auto"><b><%= HTML.escape(item.author) %></b></p>
48+
<p dir="auto"><b><%= HTML.escape(item.author) %><% if !item.author_verified.nil? && item.author_verified %><i class="icon ion ion-md-checkmark-circle"></i><% end %></b></p>
4949
</a>
5050
<% when PlaylistVideo %>
5151
<a style="width:100%" href="/watch?v=<%= item.id %>&list=<%= item.plid %>&index=<%= item.index %>">
@@ -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.author_verified.nil? && item.author_verified %><i class="icon ion ion-md-checkmark-circle"></i><% end %></p>
146146
</a></div>
147147

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

src/invidious/yt_backend/extractors.cr

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ private module Parsers
102102
premium = false
103103

104104
premiere_timestamp = item_contents.dig?("upcomingEventData", "startTime").try { |t| Time.unix(t.as_s.to_i64) }
105+
author_verified_badge = item_contents["ownerBadges"]?.try do |badges_array|
106+
badges_array.as_a.find(&.dig("metadataBadgeRenderer", "tooltip").as_s.== "Verified")
107+
end
105108

109+
author_verified = (author_verified_badge && author_verified_badge.size > 0)
106110
item_contents["badges"]?.try &.as_a.each do |badge|
107111
b = badge["metadataBadgeRenderer"]
108112
case b["label"].as_s
@@ -129,6 +133,7 @@ private module Parsers
129133
live_now: live_now,
130134
premium: premium,
131135
premiere_timestamp: premiere_timestamp,
136+
author_verified: author_verified || false,
132137
})
133138
end
134139

@@ -156,7 +161,11 @@ private module Parsers
156161
private def self.parse(item_contents, author_fallback)
157162
author = extract_text(item_contents["title"]) || author_fallback.name
158163
author_id = item_contents["channelId"]?.try &.as_s || author_fallback.id
164+
author_verified_badge = item_contents["ownerBadges"]?.try do |badges_array|
165+
badges_array.as_a.find(&.dig("metadataBadgeRenderer", "tooltip").as_s.== "Verified")
166+
end
159167

168+
author_verified = (author_verified_badge && author_verified_badge.size > 0)
160169
author_thumbnail = HelperExtractors.get_thumbnails(item_contents)
161170
# When public subscriber count is disabled, the subscriberCountText isn't sent by InnerTube.
162171
# Always simpleText
@@ -179,6 +188,7 @@ private module Parsers
179188
video_count: video_count,
180189
description_html: description_html,
181190
auto_generated: auto_generated,
191+
author_verified: author_verified || false,
182192
})
183193
end
184194

@@ -206,18 +216,23 @@ private module Parsers
206216
private def self.parse(item_contents, author_fallback)
207217
title = extract_text(item_contents["title"]) || ""
208218
plid = item_contents["playlistId"]?.try &.as_s || ""
219+
author_verified_badge = item_contents["ownerBadges"]?.try do |badges_array|
220+
badges_array.as_a.find(&.dig("metadataBadgeRenderer", "tooltip").as_s.== "Verified")
221+
end
209222

223+
author_verified = (author_verified_badge && author_verified_badge.size > 0)
210224
video_count = HelperExtractors.get_video_count(item_contents)
211225
playlist_thumbnail = HelperExtractors.get_thumbnails(item_contents)
212226

213227
SearchPlaylist.new({
214-
title: title,
215-
id: plid,
216-
author: author_fallback.name,
217-
ucid: author_fallback.id,
218-
video_count: video_count,
219-
videos: [] of SearchPlaylistVideo,
220-
thumbnail: playlist_thumbnail,
228+
title: title,
229+
id: plid,
230+
author: author_fallback.name,
231+
ucid: author_fallback.id,
232+
video_count: video_count,
233+
videos: [] of SearchPlaylistVideo,
234+
thumbnail: playlist_thumbnail,
235+
author_verified: author_verified || false,
221236
})
222237
end
223238

@@ -251,7 +266,11 @@ private module Parsers
251266
author_info = item_contents.dig?("shortBylineText", "runs", 0)
252267
author = author_info.try &.["text"].as_s || author_fallback.name
253268
author_id = author_info.try { |x| HelperExtractors.get_browse_id(x) } || author_fallback.id
269+
author_verified_badge = item_contents["ownerBadges"]?.try do |badges_array|
270+
badges_array.as_a.find(&.dig("metadataBadgeRenderer", "tooltip").as_s.== "Verified")
271+
end
254272

273+
author_verified = (author_verified_badge && author_verified_badge.size > 0)
255274
videos = item_contents["videos"]?.try &.as_a.map do |v|
256275
v = v["childVideoRenderer"]
257276
v_title = v.dig?("title", "simpleText").try &.as_s || ""
@@ -267,13 +286,14 @@ private module Parsers
267286
# TODO: item_contents["publishedTimeText"]?
268287

269288
SearchPlaylist.new({
270-
title: title,
271-
id: plid,
272-
author: author,
273-
ucid: author_id,
274-
video_count: video_count,
275-
videos: videos,
276-
thumbnail: playlist_thumbnail,
289+
title: title,
290+
id: plid,
291+
author: author,
292+
ucid: author_id,
293+
video_count: video_count,
294+
videos: videos,
295+
thumbnail: playlist_thumbnail,
296+
author_verified: author_verified || false,
277297
})
278298
end
279299

0 commit comments

Comments
 (0)