From 1bcebadef3b0ac836b3f0b8ee5df30f7c493cf38 Mon Sep 17 00:00:00 2001 From: Miguel Ángel Moreno Date: Tue, 3 Dec 2024 22:38:58 +0100 Subject: feat: add fallback tab to paginated channel api handler --- src/backend/tubo/api.clj | 55 +++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/backend/tubo/api.clj b/src/backend/tubo/api.clj index 3c0ba2e..802057f 100644 --- a/src/backend/tubo/api.clj +++ b/src/backend/tubo/api.clj @@ -73,19 +73,19 @@ (defn get-channel ([url] - (let [info (ChannelInfo/getInfo (url-decode url)) - service (NewPipe/getServiceByUrl (url-decode url)) - preloaded-videos-tab (->> (.getTabs info) - (filter #(instance? - ReadyChannelTabListLinkHandler - %)) - (filter #(some #{ChannelTabs/VIDEOS} - (.getContentFilters %))) - first) - tab-info (ChannelTabInfo/getInfo - service - (or preloaded-videos-tab - (first (.getTabs info))))] + (let [info (ChannelInfo/getInfo (url-decode url)) + service (NewPipe/getServiceByUrl (url-decode url)) + videos-tab (->> (.getTabs info) + (filter #(instance? + ReadyChannelTabListLinkHandler + %)) + (filter #(some #{ChannelTabs/VIDEOS} + (.getContentFilters %))) + first) + tab-info (ChannelTabInfo/getInfo + service + (or videos-tab + (first (.getTabs info))))] {:name (.getName info) :service-id (.getServiceId info) :id (.getId info) @@ -100,19 +100,20 @@ :related-streams (when tab-info (get-items (.getRelatedItems tab-info)))})) ([url page-url] - (let [channel-info (ChannelInfo/getInfo (url-decode url)) - service (NewPipe/getServiceByUrl (url-decode url)) - preloaded-videos-tab (->> (.getTabs channel-info) - (filter #(instance? - ReadyChannelTabListLinkHandler - %)) - (filter #(some #{ChannelTabs/VIDEOS} - (.getContentFilters %))) - first) - tab-info (ChannelTabInfo/getMoreItems service - preloaded-videos-tab - (Page. (url-decode - page-url)))] + (let [channel-info (ChannelInfo/getInfo (url-decode url)) + service (NewPipe/getServiceByUrl (url-decode url)) + videos-tab (->> (.getTabs channel-info) + (filter #(instance? + ReadyChannelTabListLinkHandler + %)) + (filter #(some #{ChannelTabs/VIDEOS} + (.getContentFilters %))) + first) + tab-info (ChannelTabInfo/getMoreItems + service + (or videos-tab (first (.getTabs channel-info))) + (Page. (url-decode + page-url)))] {:related-streams (get-items (.getRelatedItems tab-info)) :next-page (j/from-java (.getNextPage tab-info))}))) @@ -207,6 +208,8 @@ :uploader-url (.getUploaderUrl item) :uploader-avatars (j/from-java (.getUploaderAvatars item)) :uploader-verified? (.isUploaderVerified item) + :creator-reply? (.hasCreatorReply item) + :channel-owner? (.isChannelOwner item) :like-count (non-negative (.getLikeCount item)) :reply-count (non-negative (.getReplyCount item)) :hearted-by-uploader? (.isHeartedByUploader item) -- cgit v1.2.3