Skip to content

Commit aa09bbe

Browse files
committed
Done some refactoring
1 parent a09fbad commit aa09bbe

File tree

9 files changed

+23
-17
lines changed

9 files changed

+23
-17
lines changed

src/invidious/channels/about.cr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ def get_about_info(ucid, locale) : AboutChannel
7171
# if banner.includes? "channels/c4/default_banner"
7272
# banner = nil
7373
# end
74-
author_verified_badges = initdata["header"]?.try &.["c4TabbedHeaderRenderer"]?.try &.["badges"]?
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")
7577

76-
author_verified = (author_verified_badges && author_verified_badges.size > 0)
7778
description = initdata["metadata"]["channelMetadataRenderer"]?.try &.["description"]?.try &.as_s? || ""
7879
description_html = HTML.escape(description)
7980

src/invidious/comments.cr

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

146146
content_html = node_comment["contentText"]?.try { |t| parse_content(t) } || ""
147147
author = node_comment["authorText"]?.try &.["simpleText"]? || ""
148-
verified = (node_comment["authorCommentBadge"]? != nil)
149-
json.field "verified", (verified || false)
148+
149+
json.field "verified", (node_comment["authorCommentBadge"]? != nil)
150+
150151
json.field "author", author
151152
json.field "authorThumbnails" do
152153
json.array do

src/invidious/helpers/serialized_yt_data.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ struct SearchPlaylist
142142
json.field "author", self.author
143143
json.field "authorId", self.ucid
144144
json.field "authorUrl", "/channel/#{self.ucid}"
145+
145146
json.field "authorVerified", self.author_verified
147+
146148
json.field "videoCount", self.video_count
147149
json.field "videos" do
148150
json.array do

src/invidious/videos.cr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ struct Video
594594
end
595595

596596
def author_verified : Bool
597-
info["authorVerified"].as_bool
597+
info["authorVerified"].try &.as_bool || false
598598
end
599599

600600
def sub_count_text : String
@@ -854,6 +854,7 @@ def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)?
854854
end
855855

856856
author_verified = (author_verified_badge && author_verified_badge.size > 0).to_s
857+
857858
ucid = channel_info.try { |ci| HelperExtractors.get_browse_id(ci) }
858859

859860
# "4,088,033 views", only available on compact renderer
@@ -1071,9 +1072,10 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_
10711072

10721073
author_info = video_secondary_renderer.try &.dig?("owner", "videoOwnerRenderer")
10731074
author_thumbnail = author_info.try &.dig?("thumbnail", "thumbnails", 0, "url")
1074-
author_verified_badge = author_info.try &.["badges"]?
10751075

1076-
params["authorVerified"] = JSON::Any.new((author_verified_badge && author_verified_badge.size > 0) || false)
1076+
author_verified_badge = author_info.try &.dig?("badges", 0, "metadataBadgeRenderer", "tooltip")
1077+
params["authorVerified"] = JSON::Any.new((author_verified_badge && author_verified_badge == "Verified"))
1078+
10771079
params["authorThumbnail"] = JSON::Any.new(author_thumbnail.try &.as_s || "")
10781080

10791081
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><% if !channel.verified.nil? && channel.verified %> <i class="icon ion ion-md-checkmark-circle"></i><% end %>
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><% if !channel.verified.nil? && channel.verified %> <i class="icon ion ion-md-checkmark-circle"></i><% end %>
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: 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) %><% if !item.author_verified.nil? && item.author_verified %> <i class="icon ion ion-md-checkmark-circle"></i><% end %></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) %><% if !item.is_a?(InvidiousPlaylist) && !item.author_verified.nil? && item.author_verified %> <i class="icon ion ion-md-checkmark-circle"></i><% end %></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 %>">
@@ -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) %><% if !item.is_a?(MixVideo) && !item.author_verified.nil? && item.author_verified %> <i class="icon ion ion-md-checkmark-circle"></i><% end %></b></p>
48+
<p dir="auto"><b><%= HTML.escape(item.author) %></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) %><% if !item.is_a?(ChannelVideo) && !item.author_verified.nil? && item.author_verified %> <i class="icon ion ion-md-checkmark-circle"></i><% end %></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><% if !channel.verified.nil? && channel.verified %> <i class="icon ion ion-md-checkmark-circle"></i><% end %>
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
@@ -206,7 +206,7 @@ we're going to need to do it here in order to allow for translations.
206206
<% if !video.author_thumbnail.empty? %>
207207
<img src="/ggpht<%= URI.parse(video.author_thumbnail).request_target %>">
208208
<% end %>
209-
<span id="channel-name"><%= author %><% if !video.author_verified.nil? && video.author_verified %> <i class="icon ion ion-md-checkmark-circle"></i><% end %></span>
209+
<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>
210210
</div>
211211
</a>
212212
@@ -280,9 +280,9 @@ we're going to need to do it here in order to allow for translations.
280280
<h5 class="pure-g">
281281
<div class="pure-u-14-24">
282282
<% if rv["ucid"]? %>
283-
<b style="width:100%"><a href="/channel/<%= rv["ucid"] %>"><%= rv["author"]? %><% if rv["author_verified"]? == "true" %> <i class="icon ion ion-md-checkmark-circle"></i><% end %></a></b>
283+
<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>
284284
<% else %>
285-
<b style="width:100%"><%= rv["author"]? %><% if rv["author_verified"]? == "true" %> <i class="icon ion ion-md-checkmark-circle"></i><% end %></b>
285+
<b style="width:100%"><%= rv["author"]? %><% if rv["author_verified"]? == "true" %>&nbsp;<i class="icon ion ion-md-checkmark-circle"></i><% end %></b>
286286
<% end %>
287287
</div>
288288

0 commit comments

Comments
 (0)