Skip to content

Commit

Permalink
API: Parse channel's tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkyProgrammer committed Nov 26, 2023
1 parent 9ce9c54 commit 3c02377
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/invidious/channels/about.cr
Expand Up @@ -14,6 +14,7 @@ record AboutChannel,
is_family_friendly : Bool,
allowed_regions : Array(String),
tabs : Array(String),
tags : Array(String),
verified : Bool

def get_about_info(ucid, locale) : AboutChannel
Expand Down Expand Up @@ -43,6 +44,8 @@ def get_about_info(ucid, locale) : AboutChannel
auto_generated = true
end

tags = [] of String

if auto_generated
author = initdata["header"]["interactiveTabbedHeaderRenderer"]["title"]["simpleText"].as_s
author_url = initdata["microformat"]["microformatDataRenderer"]["urlCanonical"].as_s
Expand All @@ -52,7 +55,13 @@ def get_about_info(ucid, locale) : AboutChannel
banners = initdata["header"]["interactiveTabbedHeaderRenderer"]?.try &.["banner"]?.try &.["thumbnails"]?
banner = banners.try &.[-1]?.try &.["url"].as_s?

description_node = initdata["header"]["interactiveTabbedHeaderRenderer"]["description"]
description_base_node = initdata["header"]["interactiveTabbedHeaderRenderer"]["description"]
# some channels have the description in a simpleText
# ex: https://www.youtube.com/channel/UCQvWX73GQygcwXOTSf_VDVg/
description_node = description_base_node.dig?("simpleText") || description_base_node

tags = initdata.dig?("header", "interactiveTabbedHeaderRenderer", "badges")
.try &.as_a.map(&.["metadataBadgeRenderer"]["label"].as_s) || [] of String
else
author = initdata["metadata"]["channelMetadataRenderer"]["title"].as_s
author_url = initdata["metadata"]["channelMetadataRenderer"]["channelUrl"].as_s
Expand All @@ -70,6 +79,7 @@ def get_about_info(ucid, locale) : AboutChannel
# end

description_node = initdata["metadata"]["channelMetadataRenderer"]?.try &.["description"]?
tags = initdata.dig?("microformat", "microformatDataRenderer", "tags").try &.as_a.map(&.as_s) || [] of String
end

is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool
Expand Down Expand Up @@ -131,7 +141,8 @@ def get_about_info(ucid, locale) : AboutChannel
# ["description"]["simpleText"] and ["primaryLinks"][0]["title"]["simpleText"]
auto_generated = (
(channel_about_meta["primaryLinks"]?.try &.size) == 1 && \
extract_text(channel_about_meta.dig?("primaryLinks", 0, "title")) == "Auto-generated by YouTube"
extract_text(channel_about_meta.dig?("primaryLinks", 0, "title")) == "Auto-generated by YouTube" ||
channel_about_meta.dig?("links", 0, "channelExternalLinkViewModel", "title", "content").try &.as_s == "Auto-generated by YouTube"
)
end
end
Expand All @@ -155,6 +166,7 @@ def get_about_info(ucid, locale) : AboutChannel
is_family_friendly: is_family_friendly,
allowed_regions: allowed_regions,
tabs: tab_names,
tags: tags,
verified: author_verified || false,
)
end
Expand Down
1 change: 1 addition & 0 deletions src/invidious/routes/api/v1/channels.cr
Expand Up @@ -90,6 +90,7 @@ module Invidious::Routes::API::V1::Channels

json.field "allowedRegions", channel.allowed_regions
json.field "tabs", channel.tabs
json.field "tags", channel.tags
json.field "authorVerified", channel.verified

json.field "latestVideos" do
Expand Down

0 comments on commit 3c02377

Please sign in to comment.