From d046423d678a23e2c32dbe9a366351c5db5e5674 Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Tue, 1 Aug 2023 12:39:56 -0700 Subject: [PATCH] Channel: display playlists for autogenerated channels --- locales/en-US.json | 2 ++ src/invidious/channels/about.cr | 11 ++++++++++- src/invidious/channels/playlists.cr | 4 ++++ src/invidious/frontend/channel_page.cr | 3 --- src/invidious/routes/api/v1/channels.cr | 1 + src/invidious/routes/channels.cr | 11 ++++++----- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/locales/en-US.json b/locales/en-US.json index a9f78165..e976bb13 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -25,6 +25,8 @@ "newest": "newest", "oldest": "oldest", "popular": "popular", + "albums_and_singles": "Albums & Singles", + "created_playlists": "Created Playlists", "last": "last", "Next page": "Next page", "Previous page": "Previous page", diff --git a/src/invidious/channels/about.cr b/src/invidious/channels/about.cr index 8b60a728..8301ca43 100644 --- a/src/invidious/channels/about.cr +++ b/src/invidious/channels/about.cr @@ -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 @@ -43,6 +44,7 @@ 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 @@ -52,7 +54,12 @@ 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 @@ -70,6 +77,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 @@ -155,6 +163,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 diff --git a/src/invidious/channels/playlists.cr b/src/invidious/channels/playlists.cr index 91029fe3..f1e78db2 100644 --- a/src/invidious/channels/playlists.cr +++ b/src/invidious/channels/playlists.cr @@ -19,6 +19,10 @@ def fetch_channel_playlists(ucid, author, continuation, sort_by) # Formerly "&sort=dd" # {"2:string": "playlists", "3:varint": 3, "4:varint": 1, "6:varint": 1} "EglwbGF5bGlzdHMYAyABMAE%3D" + when "albums_and_singles" + "EglwbGF5bGlzdHMgMnDNg9T2lpLClfUB" + when "created_playlists" + "EglwbGF5bGlzdHMgAQ%3D%3D" end initial_data = YoutubeAPI.browse(ucid, params: params || "") diff --git a/src/invidious/frontend/channel_page.cr b/src/invidious/frontend/channel_page.cr index fe7d6d6e..84f3dc4f 100644 --- a/src/invidious/frontend/channel_page.cr +++ b/src/invidious/frontend/channel_page.cr @@ -17,9 +17,6 @@ module Invidious::Frontend::ChannelPage base_url = "/channel/#{channel.ucid}" TabsAvailable.each do |tab| - # Ignore playlists, as it is not supported for auto-generated channels yet - next if (tab.playlists? && channel.auto_generated) - tab_name = tab.to_s.downcase if channel.tabs.includes? tab_name diff --git a/src/invidious/routes/api/v1/channels.cr b/src/invidious/routes/api/v1/channels.cr index 67018660..1d409c79 100644 --- a/src/invidious/routes/api/v1/channels.cr +++ b/src/invidious/routes/api/v1/channels.cr @@ -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 diff --git a/src/invidious/routes/channels.cr b/src/invidious/routes/channels.cr index d4d8b1c1..087d9c92 100644 --- a/src/invidious/routes/channels.cr +++ b/src/invidious/routes/channels.cr @@ -100,15 +100,16 @@ module Invidious::Routes::Channels locale, user, subscriptions, continuation, ucid, channel = data - sort_options = {"last", "oldest", "newest"} - sort_by = env.params.query["sort_by"]?.try &.downcase - if channel.auto_generated - return env.redirect "/channel/#{channel.ucid}" + sort_options = {"albums_and_singles", "created_playlists"} + sort_by = env.params.query["sort_by"]?.try &.downcase || sort_options[0] + else + sort_options = {"last", "oldest", "newest"} + sort_by = env.params.query["sort_by"]?.try &.downcase || sort_options[0] end items, next_continuation = fetch_channel_playlists( - channel.ucid, channel.author, continuation, (sort_by || "last") + channel.ucid, channel.author, continuation, (sort_by) ) items = items.select(SearchPlaylist)