Skip to content

Commit

Permalink
Channel: parse subscriber count and channel banner
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkyProgrammer committed Jul 9, 2024
1 parent 1ae14cc commit 911dad6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/invidious/channels/about.cr
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def get_about_info(ucid, locale) : AboutChannel

# Raises a KeyError on failure.
banners = initdata["header"]["c4TabbedHeaderRenderer"]?.try &.["banner"]?.try &.["thumbnails"]?
banners ||= initdata.dig?("header", "pageHeaderRenderer", "content", "pageHeaderViewModel", "banner", "imageBannerViewModel", "image", "sources")
banner = banners.try &.[-1]?.try &.["url"].as_s?

# if banner.includes? "channels/c4/default_banner"
Expand Down Expand Up @@ -147,9 +148,17 @@ def get_about_info(ucid, locale) : AboutChannel
end
end

sub_count = initdata
.dig?("header", "c4TabbedHeaderRenderer", "subscriberCountText", "simpleText").try &.as_s?
.try { |text| short_text_to_number(text.split(" ")[0]).to_i32 } || 0
sub_count = 0

if (metadata_rows = initdata.dig?("header", "pageHeaderRenderer", "content", "pageHeaderViewModel", "metadata", "contentMetadataViewModel", "metadataRows").try &.as_a)
metadata_rows.each do |row|
metadata_part = row.dig?("metadataParts").try &.as_a.find { |i| i.dig?("text", "content").try &.as_s.includes?("subscribers") }
if !metadata_part.nil?
sub_count = short_text_to_number(metadata_part.dig("text", "content").as_s.split(" ")[0]).to_i32
end
break if sub_count != 0
end
end

AboutChannel.new(
ucid: ucid,
Expand Down

0 comments on commit 911dad6

Please sign in to comment.