aboutsummaryrefslogtreecommitdiff
path: root/src/backend/tau/api/kiosk.clj
blob: 81e0030cf65bc19f16db1276dec1bef1b8862e89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)})))