mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-10 01:01:57 +01:00
API: Parse channel's tags (#4294)
Example from an auto generated channel (Minecraft - Topic): /api/v1/channels/UCQvWX73GQygcwXOTSf_VDVg { ... "tags":[ "Video game","Indie game","Xbox One","New Nintendo 3DS", "PS3","Nintendo Switch","Wii U","Fire OS", "Mac operating systems","Apple TV","Xbox 360", "PlayStation Vita","PS4","Windows","Linux","Nintendo 3DS", "iOS","Windows Phone","iPadOS","Java","Android","tvOS", "ChromeOS" ] ... } Example from another channel (Mr Beast): /api/v1/channels/UCX6OQ3DkcsbYNE6H8uQQuVA { ... "tags":["mrbeast6000","beast","mrbeast","Mr.Beast","mr"] ... } No associated issue
This commit is contained in:
commit
b163afecb7
2 changed files with 15 additions and 2 deletions
|
@ -14,6 +14,7 @@ record AboutChannel,
|
||||||
is_family_friendly : Bool,
|
is_family_friendly : Bool,
|
||||||
allowed_regions : Array(String),
|
allowed_regions : Array(String),
|
||||||
tabs : Array(String),
|
tabs : Array(String),
|
||||||
|
tags : Array(String),
|
||||||
verified : Bool
|
verified : Bool
|
||||||
|
|
||||||
def get_about_info(ucid, locale) : AboutChannel
|
def get_about_info(ucid, locale) : AboutChannel
|
||||||
|
@ -43,6 +44,8 @@ def get_about_info(ucid, locale) : AboutChannel
|
||||||
auto_generated = true
|
auto_generated = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
tags = [] of String
|
||||||
|
|
||||||
if auto_generated
|
if auto_generated
|
||||||
author = initdata["header"]["interactiveTabbedHeaderRenderer"]["title"]["simpleText"].as_s
|
author = initdata["header"]["interactiveTabbedHeaderRenderer"]["title"]["simpleText"].as_s
|
||||||
author_url = initdata["microformat"]["microformatDataRenderer"]["urlCanonical"].as_s
|
author_url = initdata["microformat"]["microformatDataRenderer"]["urlCanonical"].as_s
|
||||||
|
@ -52,7 +55,13 @@ def get_about_info(ucid, locale) : AboutChannel
|
||||||
banners = initdata["header"]["interactiveTabbedHeaderRenderer"]?.try &.["banner"]?.try &.["thumbnails"]?
|
banners = initdata["header"]["interactiveTabbedHeaderRenderer"]?.try &.["banner"]?.try &.["thumbnails"]?
|
||||||
banner = banners.try &.[-1]?.try &.["url"].as_s?
|
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
|
else
|
||||||
author = initdata["metadata"]["channelMetadataRenderer"]["title"].as_s
|
author = initdata["metadata"]["channelMetadataRenderer"]["title"].as_s
|
||||||
author_url = initdata["metadata"]["channelMetadataRenderer"]["channelUrl"].as_s
|
author_url = initdata["metadata"]["channelMetadataRenderer"]["channelUrl"].as_s
|
||||||
|
@ -70,6 +79,7 @@ def get_about_info(ucid, locale) : AboutChannel
|
||||||
# end
|
# end
|
||||||
|
|
||||||
description_node = initdata["metadata"]["channelMetadataRenderer"]?.try &.["description"]?
|
description_node = initdata["metadata"]["channelMetadataRenderer"]?.try &.["description"]?
|
||||||
|
tags = initdata.dig?("microformat", "microformatDataRenderer", "tags").try &.as_a.map(&.as_s) || [] of String
|
||||||
end
|
end
|
||||||
|
|
||||||
is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool
|
is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool
|
||||||
|
@ -131,7 +141,8 @@ def get_about_info(ucid, locale) : AboutChannel
|
||||||
# ["description"]["simpleText"] and ["primaryLinks"][0]["title"]["simpleText"]
|
# ["description"]["simpleText"] and ["primaryLinks"][0]["title"]["simpleText"]
|
||||||
auto_generated = (
|
auto_generated = (
|
||||||
(channel_about_meta["primaryLinks"]?.try &.size) == 1 && \
|
(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
|
||||||
end
|
end
|
||||||
|
@ -155,6 +166,7 @@ def get_about_info(ucid, locale) : AboutChannel
|
||||||
is_family_friendly: is_family_friendly,
|
is_family_friendly: is_family_friendly,
|
||||||
allowed_regions: allowed_regions,
|
allowed_regions: allowed_regions,
|
||||||
tabs: tab_names,
|
tabs: tab_names,
|
||||||
|
tags: tags,
|
||||||
verified: author_verified || false,
|
verified: author_verified || false,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -90,6 +90,7 @@ module Invidious::Routes::API::V1::Channels
|
||||||
|
|
||||||
json.field "allowedRegions", channel.allowed_regions
|
json.field "allowedRegions", channel.allowed_regions
|
||||||
json.field "tabs", channel.tabs
|
json.field "tabs", channel.tabs
|
||||||
|
json.field "tags", channel.tags
|
||||||
json.field "authorVerified", channel.verified
|
json.field "authorVerified", channel.verified
|
||||||
|
|
||||||
json.field "latestVideos" do
|
json.field "latestVideos" do
|
||||||
|
|
Loading…
Reference in a new issue