aboutsummaryrefslogtreecommitdiff
path: root/src/backend/tau/api/kiosk.clj
diff options
context:
space:
mode:
authorMiguel Ángel Moreno <mail@migalmoreno.com>2022-11-21 17:55:28 +0100
committerMiguel Ángel Moreno <mail@migalmoreno.com>2022-12-20 00:54:46 +0100
commit452ccfd567f79126e108f69bb7ebca07b5993bdd (patch)
tree4bc2688977dcd461259683bc89ea7eb94848f627 /src/backend/tau/api/kiosk.clj
feat: Initial commit
Diffstat (limited to 'src/backend/tau/api/kiosk.clj')
-rw-r--r--src/backend/tau/api/kiosk.clj47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/backend/tau/api/kiosk.clj b/src/backend/tau/api/kiosk.clj
new file mode 100644
index 0000000..81e0030
--- /dev/null
+++ b/src/backend/tau/api/kiosk.clj
@@ -0,0 +1,47 @@
+(ns tau.api.kiosk
+ (:require
+ [clojure.java.data :as j]
+ [tau.api.stream :as stream]
+ [ring.util.codec :refer [url-decode]])
+ (:import
+ org.schabi.newpipe.extractor.StreamingService
+ org.schabi.newpipe.extractor.Page
+ org.schabi.newpipe.extractor.kiosk.KioskInfo
+ org.schabi.newpipe.extractor.NewPipe))
+
+(defrecord KioskList
+ [default-kiosk available-kiosks])
+
+(defrecord Kiosk
+ [id url next-page related-streams])
+
+(defrecord KioskPage
+ [next-page related-streams])
+
+(defn get-kiosk-info
+ ([kiosk-id service-id]
+ (let [service (NewPipe/getService service-id)
+ extractor (.getExtractorById (.getKioskList service) kiosk-id nil)
+ info (KioskInfo/getInfo extractor)]
+ (map->Kiosk
+ {:id (.getId info)
+ :url (.getUrl info)
+ :next-page (j/from-java (.getNextPage info))
+ :related-streams (map #(stream/get-stream-result %) (.getRelatedItems info))})))
+ ([kiosk-id service-id page-url]
+ (let [service (NewPipe/getService service-id)
+ extractor (.getExtractorById (.getKioskList service) kiosk-id nil)
+ url (url-decode page-url)
+ kiosk-info (KioskInfo/getInfo extractor)
+ 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))}))))
+
+(defn get-kiosk-list-info
+ [service-id]
+ (let [service (NewPipe/getService service-id)
+ kiosks (.getKioskList service)]
+ (map->KioskList
+ {:default-kiosk (.getDefaultKioskId kiosks)
+ :available-kiosks (.getAvailableKiosks kiosks)})))