Skip to content

Commit

Permalink
Search: Parse channel handle and hide video count when channel handle…
Browse files Browse the repository at this point in the history
… exists
  • Loading branch information
ChunkyProgrammer committed Jul 18, 2023
1 parent 69e2eac commit 5f7cdbc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/invidious/helpers/serialized_yt_data.cr
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ struct SearchChannel
property author_thumbnail : String
property subscriber_count : Int32
property video_count : Int32
property channel_handle : String?
property description_html : String
property auto_generated : Bool
property author_verified : Bool
Expand Down Expand Up @@ -214,6 +215,7 @@ struct SearchChannel
json.field "autoGenerated", self.auto_generated
json.field "subCount", self.subscriber_count
json.field "videoCount", self.video_count
json.field "channelHandle", self.channel_handle

json.field "description", html_to_content(self.description_html)
json.field "descriptionHtml", self.description_html
Expand Down
3 changes: 2 additions & 1 deletion src/invidious/views/components/item.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
</a></div>
</div>

<% if !item.channel_handle.nil? %><p class="channel-name" dir="auto"><%= item.channel_handle %></p><% end %>
<p><%= translate_count(locale, "generic_subscribers_count", item.subscriber_count, NumberFormatting::Separator) %></p>
<% if !item.auto_generated %><p><%= translate_count(locale, "generic_videos_count", item.video_count, NumberFormatting::Separator) %></p><% end %>
<% if !item.auto_generated && item.channel_handle.nil? %><p><%= translate_count(locale, "generic_videos_count", item.video_count, NumberFormatting::Separator) %></p><% end %>
<h5><%= item.description_html %></h5>
<% when SearchPlaylist, InvidiousPlaylist %>
<%-
Expand Down
7 changes: 6 additions & 1 deletion src/invidious/yt_backend/extractors.cr
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ private module Parsers
# TODO change default value to nil

subscriber_count = item_contents.dig?("subscriberCountText", "simpleText")

channel_handle = nil
if subscriber_count.try &.as_s.starts_with?("@")
channel_handle = subscriber_count.try &.as_s
end
# Since youtube added channel handles, `VideoCountText` holds the number of
# subscribers and `subscriberCountText` holds the handle, except when the
# channel doesn't have a handle (e.g: some topic music channels).
Expand All @@ -191,6 +194,7 @@ private module Parsers
auto_generated = item_contents["videoCountText"]?.nil?

video_count = HelperExtractors.get_video_count(item_contents)

description_html = item_contents["descriptionSnippet"]?.try { |t| parse_content(t) } || ""

SearchChannel.new({
Expand All @@ -199,6 +203,7 @@ private module Parsers
author_thumbnail: author_thumbnail,
subscriber_count: subscriber_count,
video_count: video_count,
channel_handle: channel_handle,
description_html: description_html,
auto_generated: auto_generated,
author_verified: author_verified,
Expand Down

0 comments on commit 5f7cdbc

Please sign in to comment.