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/playlist.clj | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/backend/tau/api/playlist.clj') 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))})))) -- cgit v1.2.3