aboutsummaryrefslogtreecommitdiff
path: root/src/backend/tau/api/channel.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/channel.clj
parente4714f94ff6d01847fa61c33c678b6d856c3b30a (diff)
fix: Fix related streams on API endpoints
Diffstat (limited to 'src/backend/tau/api/channel.clj')
-rw-r--r--src/backend/tau/api/channel.clj17
1 files changed, 13 insertions, 4 deletions
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))}))))