From e71fdc8dbac5c77d6c2fd252f31fc12cd6375e30 Mon Sep 17 00:00:00 2001 From: Miguel Ángel Moreno Date: Tue, 20 Dec 2022 00:35:56 +0100 Subject: fix: Fix related streams on API endpoints --- src/backend/tau/api/channel.clj | 17 +++++++++++++---- src/backend/tau/api/comment.clj | 8 ++++---- src/backend/tau/api/kiosk.clj | 18 ++++++++++++++---- src/backend/tau/api/playlist.clj | 17 +++++++++++++---- src/backend/tau/api/search.clj | 14 +++++++------- src/backend/tau/api/service.clj | 11 ++++++----- src/backend/tau/api/stream.clj | 19 +++++++++++++++---- 7 files changed, 72 insertions(+), 32 deletions(-) (limited to 'src/backend/tau/api') diff --git a/src/backend/tau/api/channel.clj b/src/backend/tau/api/channel.clj index 26d3b34..8ef29e5 100644 --- a/src/backend/tau/api/channel.clj +++ b/src/backend/tau/api/channel.clj @@ -1,6 +1,7 @@ (ns tau.api.channel (:require [tau.api.stream :as stream] + [tau.api.playlist :as playlist] [clojure.java.data :as j] [ring.util.codec :refer [url-decode]]) (:import @@ -20,7 +21,15 @@ (defrecord ChannelPage [next-page related-streams]) -(defn get-channel-result +(defn get-results + [items] + (map #(case (.name (.getInfoType %)) + "STREAM" (stream/get-result %) + "CHANNEL" (get-result %) + "PLAYLIST" (playlist/get-result %)) + items)) + +(defn get-result [channel] (map->ChannelResult {:name (.getName channel) @@ -31,7 +40,7 @@ :stream-count (.getStreamCount channel) :verified? (.isVerified channel)})) -(defn get-channel-info +(defn get-info ([url] (let [info (ChannelInfo/getInfo (url-decode url))] (map->Channel @@ -43,10 +52,10 @@ :subscriber-count (.getSubscriberCount info) :donation-links (.getDonationLinks info) :next-page (j/from-java (.getNextPage info)) - :related-streams (map #(stream/get-stream-result %) (.getRelatedItems info))}))) + :related-streams (get-results (.getRelatedItems info))}))) ([url page-url] (let [service (NewPipe/getServiceByUrl (url-decode url)) info (ChannelInfo/getMoreItems service url (Page. (url-decode page-url)))] (map->ChannelPage - {:related-streams (map #(stream/get-stream-result %) (.getItems info)) + {:related-streams (get-results (.getItems info)) :next-page (j/from-java (.getNextPage info))})))) diff --git a/src/backend/tau/api/comment.clj b/src/backend/tau/api/comment.clj index 18881cb..956090e 100644 --- a/src/backend/tau/api/comment.clj +++ b/src/backend/tau/api/comment.clj @@ -15,7 +15,7 @@ [id text upload-name upload-avatar upload-date upload-url upload-verified? like-count hearted-by-upload? pinned? replies]) -(defn get-comment-result +(defn get-result [comment] (map->Comment {:id (.getCommentId comment) @@ -31,17 +31,17 @@ :replies (when (.getReplies comment) (j/from-java (.getReplies comment)))})) -(defn get-comments-info +(defn get-info ([url] (let [info (CommentsInfo/getInfo (url-decode url))] (map->CommentsPage - {:comments (map #(get-comment-result %) (.getRelatedItems info)) + {:comments (map #(get-result %) (.getRelatedItems info)) :next-page (j/from-java (.getNextPage info)) :disabled? (.isCommentsDisabled info)}))) ([url page-url] (let [service (NewPipe/getServiceByUrl (url-decode url)) info (CommentsInfo/getMoreItems service url (Page. (url-decode page-url)))] (map->CommentsPage - {:comments (map #(get-comment-result %) (.getItems info)) + {:comments (map #(get-result %) (.getItems info)) :next-page (j/from-java (.getNextPage info)) :disabled? false})))) diff --git a/src/backend/tau/api/kiosk.clj b/src/backend/tau/api/kiosk.clj index 81e0030..7ae2150 100644 --- a/src/backend/tau/api/kiosk.clj +++ b/src/backend/tau/api/kiosk.clj @@ -2,6 +2,8 @@ (:require [clojure.java.data :as j] [tau.api.stream :as stream] + [tau.api.channel :as channel] + [tau.api.playlist :as playlist] [ring.util.codec :refer [url-decode]]) (:import org.schabi.newpipe.extractor.StreamingService @@ -18,7 +20,15 @@ (defrecord KioskPage [next-page related-streams]) -(defn get-kiosk-info +(defn get-results + [items] + (map #(case (.name (.getInfoType %)) + "STREAM" (stream/get-result %) + "CHANNEL" (channel/get-result %) + "PLAYLIST" (playlist/get-result %)) + items)) + +(defn get-info ([kiosk-id service-id] (let [service (NewPipe/getService service-id) extractor (.getExtractorById (.getKioskList service) kiosk-id nil) @@ -27,7 +37,7 @@ {:id (.getId info) :url (.getUrl info) :next-page (j/from-java (.getNextPage info)) - :related-streams (map #(stream/get-stream-result %) (.getRelatedItems info))}))) + :related-streams (get-results (.getRelatedItems info))}))) ([kiosk-id service-id page-url] (let [service (NewPipe/getService service-id) extractor (.getExtractorById (.getKioskList service) kiosk-id nil) @@ -36,9 +46,9 @@ info (KioskInfo/getMoreItems service (.getUrl kiosk-info) (Page. url))] (map->KioskPage {:next-page (j/from-java (.getNextPage info)) - :related-streams (map #(stream/get-stream-result %) (.getItems info))})))) + :related-streams (get-results (.getItems info))})))) -(defn get-kiosk-list-info +(defn get-kiosks [service-id] (let [service (NewPipe/getService service-id) kiosks (.getKioskList service)] diff --git a/src/backend/tau/api/playlist.clj b/src/backend/tau/api/playlist.clj index ccc0d6a..4bc7054 100644 --- a/src/backend/tau/api/playlist.clj +++ b/src/backend/tau/api/playlist.clj @@ -2,6 +2,7 @@ (:require [clojure.java.data :as j] [tau.api.stream :as stream] + [tau.api.channel :as channel] [ring.util.codec :refer [url-decode]]) (:import org.schabi.newpipe.extractor.playlist.PlaylistInfo @@ -18,7 +19,15 @@ (defrecord PlaylistPage [next-page related-streams]) -(defn get-playlist-result +(defn get-results + [items] + (map #(case (.name (.getInfoType %)) + "STREAM" (stream/get-result %) + "CHANNEL" (channel/get-result %) + "PLAYLIST" (get-result %)) + items)) + +(defn get-result [playlist] (map->PlaylistResult {:name (.getName playlist) @@ -27,7 +36,7 @@ :upload-author (.getUploaderName playlist) :stream-count (.getStreamCount playlist)})) -(defn get-playlist-info +(defn get-info ([url] (let [service (NewPipe/getServiceByUrl (url-decode url)) info (PlaylistInfo/getInfo service (url-decode url))] @@ -42,10 +51,10 @@ :uploader-avatar (.getUploaderAvatarUrl info) :stream-count (.getStreamCount info) :next-page (j/from-java (.getNextPage info)) - :related-streams (map #(stream/get-stream-result %) (.getRelatedItems info))}))) + :related-streams (get-results (.getRelatedItems info))}))) ([url page-url] (let [service (NewPipe/getServiceByUrl (url-decode url)) info (PlaylistInfo/getMoreItems service url (Page. (url-decode page-url)))] (map->PlaylistPage {:next-page (j/from-java (.getNextPage info)) - :related-streams (map #(stream/get-stream-result %) (.getItems info))})))) + :related-streams (get-results (.getItems info))})))) diff --git a/src/backend/tau/api/search.clj b/src/backend/tau/api/search.clj index 4969f10..106999d 100644 --- a/src/backend/tau/api/search.clj +++ b/src/backend/tau/api/search.clj @@ -17,15 +17,15 @@ (defrecord SearchResultPage [items next-page]) -(defn get-search-results +(defn get-results [items] (map #(case (.name (.getInfoType %)) - "STREAM" (stream/get-stream-result %) - "CHANNEL" (channel/get-channel-result %) - "PLAYLIST" (playlist/get-playlist-result %)) + "STREAM" (stream/get-result %) + "CHANNEL" (channel/get-result %) + "PLAYLIST" (playlist/get-result %)) items)) -(defn get-search-info +(defn get-info ([service-id query content-filters sort-filter] (let [service (NewPipe/getService service-id) query-handler (.. service @@ -33,7 +33,7 @@ (fromQuery query (or content-filters '()) (or sort-filter ""))) info (SearchInfo/getInfo service query-handler)] (map->SearchResult - {:items (get-search-results (.getRelatedItems info)) + {:items (get-results (.getRelatedItems info)) :next-page (j/from-java (.getNextPage info)) :search-suggestion (.getSearchSuggestion info) :corrected-search? (.isCorrectedSearch info)}))) @@ -45,5 +45,5 @@ (fromQuery query (or content-filters '()) (or sort-filter ""))) info (SearchInfo/getMoreItems service query-handler (Page. url))] (map->SearchResultPage - {:items (get-search-results (.getItems info)) + {:items (get-results (.getItems info)) :next-page (j/from-java (.getNextPage info))})))) diff --git a/src/backend/tau/api/service.clj b/src/backend/tau/api/service.clj index de2e994..b9f0e1d 100644 --- a/src/backend/tau/api/service.clj +++ b/src/backend/tau/api/service.clj @@ -10,15 +10,16 @@ (defrecord Service [id info base-url kiosk-list]) -(defn get-service-info +(defn get-info [service] (map->Service {:id (.getServiceId service) :info (j/from-java (.getServiceInfo service)) :base-url (.getBaseUrl service) - :kiosk-list (map #(kiosk/get-kiosk-info % (.getServiceId service)) - (.getAvailableKiosks (.getKioskList service)))})) + ;; :kiosk-list (map #(kiosk/get-info % (.getServiceId service)) + ;; (.getAvailableKiosks (.getKioskList service))) + })) -(defn get-service-list-info +(defn get-services [] - (map #(get-service-info %) (NewPipe/getServices))) + (map #(get-info %) (NewPipe/getServices))) diff --git a/src/backend/tau/api/stream.clj b/src/backend/tau/api/stream.clj index d0a7c81..63ab183 100644 --- a/src/backend/tau/api/stream.clj +++ b/src/backend/tau/api/stream.clj @@ -1,5 +1,7 @@ (ns tau.api.stream (:require + [tau.api.playlist :as playlist] + [tau.api.channel :as channel] [clojure.java.data :as j] [ring.util.codec :refer [url-decode]]) (:import @@ -21,7 +23,7 @@ upload-avatar upload-date short-description duration view-count uploaded verified?]) -(defn get-stream-result +(defn get-result [stream] (map->StreamResult {:url (.getUrl stream) @@ -36,14 +38,23 @@ :view-count (.getViewCount stream) :uploaded (if (.getUploadDate stream) (.. stream (getUploadDate) (offsetDateTime) (toInstant) (toEpochMilli)) - -1) + false) :verified? (.isUploaderVerified stream)})) -(defn get-stream-info +(defn get-results + [items] + (map #(case (.name (.getInfoType %)) + "STREAM" (get-result %) + "CHANNEL" (channel/get-result %) + "PLAYLIST" (playlist/get-result %)) + items)) + +(defn get-info [url] (let [info (StreamInfo/getInfo (url-decode url))] (map->Stream {:name (.getName info) + :url (.getUrl info) :description (.. info (getDescription) (getContent)) :upload-date (.getTextualUploadDate info) :upload-author (.getUploaderName info) @@ -63,4 +74,4 @@ :video-streams (j/from-java (.getVideoStreams info)) :hls-url (.getHlsUrl info) :dash-mpd-url (.getDashMpdUrl info) - :related-streams (map #(get-stream-result %) (.getRelatedStreams info))}))) + :related-streams (get-results (.getRelatedStreams info))}))) -- cgit v1.2.3