aboutsummaryrefslogtreecommitdiff
path: root/src/backend/tau/api/playlist.clj
diff options
context:
space:
mode:
authorMiguel Ángel Moreno <mail@migalmoreno.com>2022-12-20 00:35:56 +0100
committerMiguel Ángel Moreno <mail@migalmoreno.com>2022-12-20 00:54:58 +0100
commite71fdc8dbac5c77d6c2fd252f31fc12cd6375e30 (patch)
tree890953876b06a647e6790715f2580aa94aebe4a7 /src/backend/tau/api/playlist.clj
parente4714f94ff6d01847fa61c33c678b6d856c3b30a (diff)
fix: Fix related streams on API endpoints
Diffstat (limited to 'src/backend/tau/api/playlist.clj')
-rw-r--r--src/backend/tau/api/playlist.clj17
1 files changed, 13 insertions, 4 deletions
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))}))))