blob: 8b9638fa84243daee8d38089efdd08ef8f60ede5 (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
(ns tau.api.services
(:require
[clojure.java.data :as j]
[ring.util.codec :refer [url-encode url-decode]]
[tau.api.items :as items])
(:import
org.schabi.newpipe.extractor.kiosk.KioskInfo
org.schabi.newpipe.extractor.kiosk.KioskList
org.schabi.newpipe.extractor.InfoItem
org.schabi.newpipe.extractor.NewPipe
org.schabi.newpipe.extractor.Page
org.schabi.newpipe.extractor.StreamingService
org.schabi.newpipe.extractor.search.SearchInfo))
(defn search
([service-id query content-filters sort-filter]
(let [service (NewPipe/getService service-id)
query-handler (.. service
(getSearchQHFactory)
(fromQuery query (or content-filters '()) (or sort-filter "")))
info (SearchInfo/getInfo service query-handler)]
{:items (items/get-items (.getRelatedItems info))
:next-page (j/from-java (.getNextPage info))
:search-suggestion (.getSearchSuggestion info)
:corrected-search? (.isCorrectedSearch info)}))
([service-id query content-filters sort-filter page-url]
(let [service (NewPipe/getService service-id)
url (url-decode page-url)
query-handler (.. service
(getSearchQHFactory)
(fromQuery query (or content-filters '()) (or sort-filter "")))
info (SearchInfo/getMoreItems service query-handler (Page. url))]
{:items (items/get-items (.getItems info))
:next-page (j/from-java (.getNextPage info))})))
(defn get-kiosk
([service-id]
(let [service (NewPipe/getService service-id)
extractor (doto (.getDefaultKioskExtractor (.getKioskList service))
(.fetchPage))
info (KioskInfo/getInfo extractor)]
{:id (.getId info)
:url (.getUrl info)
:next-page (j/from-java (.getNextPage info))
:related-streams (items/get-items (.getRelatedItems info))}))
([kiosk-id service-id]
(let [service (NewPipe/getService service-id)
extractor (doto (.getExtractorById (.getKioskList service) kiosk-id nil)
(.fetchPage))
info (KioskInfo/getInfo extractor)]
{:id (.getId info)
:url (.getUrl info)
:next-page (j/from-java (.getNextPage info))
:related-streams (items/get-items (.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))]
{:next-page (j/from-java (.getNextPage info))
:related-streams (items/get-items (.getItems info))})))
(defn get-kiosks
[service-id]
(let [service (NewPipe/getService service-id)
kiosks (.getKioskList service)]
{:default-kiosk (.getDefaultKioskId kiosks)
:available-kiosks (.getAvailableKiosks kiosks)}))
(defn get-service
[service]
{:id (.getServiceId service)
:info (j/from-java (.getServiceInfo service))
:base-url (.getBaseUrl service)})
(defn get-services
[]
(map get-service (NewPipe/getServices)))
|