aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel Ángel Moreno <mail@migalmoreno.com>2022-12-29 01:53:08 +0100
committerMiguel Ángel Moreno <mail@migalmoreno.com>2022-12-29 01:53:08 +0100
commitdfcc61063822dfb0fe699896da312249e93d5439 (patch)
treec1dc29de45cfe4ae67f104510dc3c4b6d858aa46
parent6382ec24c5bbbf93ced1e587103a52b3a63e6045 (diff)
feat(backend): Remove records and simplify API
-rw-r--r--src/backend/tau/api/channel.clj38
-rw-r--r--src/backend/tau/api/channels.clj28
-rw-r--r--src/backend/tau/api/comment.clj47
-rw-r--r--src/backend/tau/api/comments.clj37
-rw-r--r--src/backend/tau/api/items.clj47
-rw-r--r--src/backend/tau/api/kiosk.clj47
-rw-r--r--src/backend/tau/api/playlist.clj39
-rw-r--r--src/backend/tau/api/playlists.clj30
-rw-r--r--src/backend/tau/api/result.clj59
-rw-r--r--src/backend/tau/api/search.clj39
-rw-r--r--src/backend/tau/api/service.clj25
-rw-r--r--src/backend/tau/api/services.clj79
-rw-r--r--src/backend/tau/api/stream.clj45
-rw-r--r--src/backend/tau/api/streams.clj36
-rw-r--r--src/backend/tau/handler.clj41
-rw-r--r--src/backend/tau/router.clj17
16 files changed, 287 insertions, 367 deletions
diff --git a/src/backend/tau/api/channel.clj b/src/backend/tau/api/channel.clj
deleted file mode 100644
index 89c6a7c..0000000
--- a/src/backend/tau/api/channel.clj
+++ /dev/null
@@ -1,38 +0,0 @@
-(ns tau.api.channel
- (:require
- [clojure.java.data :as j]
- [ring.util.codec :refer [url-decode]]
- [tau.api.result :as result])
- (:import
- org.schabi.newpipe.extractor.channel.ChannelInfo
- org.schabi.newpipe.extractor.NewPipe
- org.schabi.newpipe.extractor.Page))
-
-(defrecord Channel
- [id name description verified? banner avatar
- subscriber-count donation-links next-page
- related-streams])
-
-(defrecord ChannelPage
- [next-page related-streams])
-
-(defn get-info
- ([url]
- (let [info (ChannelInfo/getInfo (url-decode url))]
- (map->Channel
- {:id (.getId info)
- :name (.getName info)
- :verified? (.isVerified info)
- :banner (.getBannerUrl info)
- :avatar (.getAvatarUrl info)
- :description (.getDescription info)
- :subscriber-count (if (= (.getSubscriberCount info) -1) false (.getSubscriberCount info))
- :donation-links (.getDonationLinks info)
- :next-page (j/from-java (.getNextPage info))
- :related-streams (result/get-results (.getRelatedItems info))})))
- ([url page-url]
- (let [service (NewPipe/getServiceByUrl (url-decode url))
- info (ChannelInfo/getMoreItems service (url-decode url) (Page. (url-decode page-url)))]
- (map->ChannelPage
- {:related-streams (result/get-results (.getItems info))
- :next-page (j/from-java (.getNextPage info))}))))
diff --git a/src/backend/tau/api/channels.clj b/src/backend/tau/api/channels.clj
new file mode 100644
index 0000000..695a3fd
--- /dev/null
+++ b/src/backend/tau/api/channels.clj
@@ -0,0 +1,28 @@
+(ns tau.api.channels
+ (:require
+ [clojure.java.data :as j]
+ [ring.util.codec :refer [url-decode]]
+ [tau.api.items :as items])
+ (:import
+ org.schabi.newpipe.extractor.channel.ChannelInfo
+ org.schabi.newpipe.extractor.NewPipe
+ org.schabi.newpipe.extractor.Page))
+
+(defn get-channel
+ ([url]
+ (let [info (ChannelInfo/getInfo (url-decode url))]
+ {:id (.getId info)
+ :name (.getName info)
+ :verified? (.isVerified info)
+ :banner (.getBannerUrl info)
+ :avatar (.getAvatarUrl info)
+ :description (.getDescription info)
+ :subscriber-count (when-not (= (.getSubscriberCount info) -1) (.getSubscriberCount info))
+ :donation-links (.getDonationLinks info)
+ :next-page (j/from-java (.getNextPage info))
+ :related-streams (items/get-items (.getRelatedItems info))}))
+ ([url page-url]
+ (let [service (NewPipe/getServiceByUrl (url-decode url))
+ info (ChannelInfo/getMoreItems service (url-decode url) (Page. (url-decode page-url)))]
+ {:related-streams (items/get-items (.getItems info))
+ :next-page (j/from-java (.getNextPage info))})))
diff --git a/src/backend/tau/api/comment.clj b/src/backend/tau/api/comment.clj
deleted file mode 100644
index 956090e..0000000
--- a/src/backend/tau/api/comment.clj
+++ /dev/null
@@ -1,47 +0,0 @@
-(ns tau.api.comment
- (:require
- [clojure.java.data :as j]
- [ring.util.codec :refer [url-decode]])
- (:import
- org.schabi.newpipe.extractor.NewPipe
- org.schabi.newpipe.extractor.Page
- org.schabi.newpipe.extractor.comments.CommentsInfoItem
- org.schabi.newpipe.extractor.comments.CommentsInfo))
-
-(defrecord CommentsPage
- [next-page disabled? comments])
-
-(defrecord Comment
- [id text upload-name upload-avatar upload-date upload-url
- upload-verified? like-count hearted-by-upload? pinned? replies])
-
-(defn get-result
- [comment]
- (map->Comment
- {:id (.getCommentId comment)
- :text (.getCommentText comment)
- :upload-name (.getUploaderName comment)
- :upload-avatar (.getUploaderAvatarUrl comment)
- :upload-date (.getTextualUploadDate comment)
- :upload-url (.getUploaderUrl comment)
- :upload-verified? (.isUploaderVerified comment)
- :like-count (.getLikeCount comment)
- :hearted-by-upload? (.isHeartedByUploader comment)
- :pinned? (.isPinned comment)
- :replies (when (.getReplies comment)
- (j/from-java (.getReplies comment)))}))
-
-(defn get-info
- ([url]
- (let [info (CommentsInfo/getInfo (url-decode url))]
- (map->CommentsPage
- {:comments (map #(get-result %) (.getRelatedItems info))
- :next-page (j/from-java (.getNextPage info))
- :disabled? (.isCommentsDisabled info)})))
- ([url page-url]
- (let [service (NewPipe/getServiceByUrl (url-decode url))
- info (CommentsInfo/getMoreItems service url (Page. (url-decode page-url)))]
- (map->CommentsPage
- {:comments (map #(get-result %) (.getItems info))
- :next-page (j/from-java (.getNextPage info))
- :disabled? false}))))
diff --git a/src/backend/tau/api/comments.clj b/src/backend/tau/api/comments.clj
new file mode 100644
index 0000000..477c72d
--- /dev/null
+++ b/src/backend/tau/api/comments.clj
@@ -0,0 +1,37 @@
+(ns tau.api.comments
+ (:require
+ [clojure.java.data :as j]
+ [ring.util.codec :refer [url-decode]])
+ (:import
+ org.schabi.newpipe.extractor.NewPipe
+ org.schabi.newpipe.extractor.Page
+ org.schabi.newpipe.extractor.comments.CommentsInfoItem
+ org.schabi.newpipe.extractor.comments.CommentsInfo))
+
+(defn get-comment-item
+ [item]
+ {:id (.getCommentId item)
+ :text (.getCommentText item)
+ :uploader-name (.getUploaderName item)
+ :uploader-avatar (.getUploaderAvatarUrl item)
+ :uploader-url (.getUploaderUrl item)
+ :uploader-verified? (.isUploaderVerified item)
+ :upload-date (.getTextualUploadDate item)
+ :like-count (when-not (= (.getLikeCount item) -1) (.getLikeCount item))
+ :hearted-by-uploader? (.isHeartedByUploader item)
+ :pinned? (.isPinned item)
+ :replies (when (.getReplies item)
+ (j/from-java (.getReplies item)))})
+
+(defn get-comment
+ ([url]
+ (let [info (CommentsInfo/getInfo (url-decode url))]
+ {:comments (map get-comment-item (.getRelatedItems info))
+ :next-page (j/from-java (.getNextPage info))
+ :disabled? (.isCommentsDisabled info)}))
+ ([url page-url]
+ (let [service (NewPipe/getServiceByUrl (url-decode url))
+ info (CommentsInfo/getMoreItems service url (Page. (url-decode page-url)))]
+ {:comments (map get-comment-item (.getItems info))
+ :next-page (j/from-java (.getNextPage info))
+ :disabled? false})))
diff --git a/src/backend/tau/api/items.clj b/src/backend/tau/api/items.clj
new file mode 100644
index 0000000..e251330
--- /dev/null
+++ b/src/backend/tau/api/items.clj
@@ -0,0 +1,47 @@
+(ns tau.api.items)
+
+(defn get-stream-item
+ [stream]
+ {:type :stream
+ :url (.getUrl stream)
+ :name (.getName stream)
+ :thumbnail-url (.getThumbnailUrl stream)
+ :upload-author (.getUploaderName stream)
+ :upload-url (.getUploaderUrl stream)
+ :upload-avatar (.getUploaderAvatarUrl stream)
+ :upload-date (.getTextualUploadDate stream)
+ :short-description (.getShortDescription stream)
+ :duration (.getDuration stream)
+ :view-count (when-not (= (.getViewCount stream) -1) (.getViewCount stream))
+ :uploaded (if (.getUploadDate stream)
+ (.. stream (getUploadDate) (offsetDateTime) (toInstant) (toEpochMilli))
+ false)
+ :verified? (.isUploaderVerified stream)})
+
+(defn get-channel-item
+ [channel]
+ {:type :channel
+ :url (.getUrl channel)
+ :name (.getName channel)
+ :thumbnail-url (.getThumbnailUrl channel)
+ :description (.getDescription channel)
+ :subscriber-count (when-not (= (.getSubscriberCount channel) -1) (.getSubscriberCount channel))
+ :stream-count (when-not (= (.getStreamCount channel) -1) (.getStreamCount channel))
+ :verified? (.isVerified channel)})
+
+(defn get-playlist-item
+ [playlist]
+ {:type :playlist
+ :url (.getUrl playlist)
+ :name (.getName playlist)
+ :thumbnail-url (.getThumbnailUrl playlist)
+ :upload-author (.getUploaderName playlist)
+ :stream-count (when-not (= (.getStreamCount playlist) -1) (.getStreamCount playlist))})
+
+(defn get-items
+ [items]
+ (map #(case (.name (.getInfoType %))
+ "STREAM" (get-stream-item %)
+ "CHANNEL" (get-channel-item %)
+ "PLAYLIST" (get-playlist-item %))
+ items))
diff --git a/src/backend/tau/api/kiosk.clj b/src/backend/tau/api/kiosk.clj
deleted file mode 100644
index 4243a32..0000000
--- a/src/backend/tau/api/kiosk.clj
+++ /dev/null
@@ -1,47 +0,0 @@
-(ns tau.api.kiosk
- (:require
- [clojure.java.data :as j]
- [ring.util.codec :refer [url-decode]]
- [tau.api.result :as result])
- (: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-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 (result/get-results (.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 (result/get-results (.getItems info))}))))
-
-(defn get-kiosks
- [service-id]
- (let [service (NewPipe/getService service-id)
- kiosks (.getKioskList service)]
- (map->KioskList
- {:default-kiosk (.getDefaultKioskId kiosks)
- :available-kiosks (.getAvailableKiosks kiosks)})))
diff --git a/src/backend/tau/api/playlist.clj b/src/backend/tau/api/playlist.clj
deleted file mode 100644
index 8f2b22c..0000000
--- a/src/backend/tau/api/playlist.clj
+++ /dev/null
@@ -1,39 +0,0 @@
-(ns tau.api.playlist
- (:require
- [clojure.java.data :as j]
- [ring.util.codec :refer [url-decode]]
- [tau.api.result :as result])
- (:import
- org.schabi.newpipe.extractor.playlist.PlaylistInfo
- org.schabi.newpipe.extractor.Page
- org.schabi.newpipe.extractor.NewPipe))
-
-(defrecord Playlist
- [id name playlist-type thumbnail-url uploader-name uploader-url
- uploader-avatar banner-url next-page stream-count related-streams])
-
-(defrecord PlaylistPage
- [next-page related-streams])
-
-(defn get-info
- ([url]
- (let [service (NewPipe/getServiceByUrl (url-decode url))
- info (PlaylistInfo/getInfo service (url-decode url))]
- (map->Playlist
- {:id (.getId info)
- :name (.getName info)
- :playlist-type (j/from-java (.getPlaylistType info))
- :thumbnail-url (.getThumbnailUrl info)
- :banner-url (.getBannerUrl info)
- :uploader-name (.getUploaderName info)
- :uploader-url (.getUploaderUrl info)
- :uploader-avatar (.getUploaderAvatarUrl info)
- :stream-count (.getStreamCount info)
- :next-page (j/from-java (.getNextPage info))
- :related-streams (result/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 (result/get-results (.getItems info))}))))
diff --git a/src/backend/tau/api/playlists.clj b/src/backend/tau/api/playlists.clj
new file mode 100644
index 0000000..92e8e8d
--- /dev/null
+++ b/src/backend/tau/api/playlists.clj
@@ -0,0 +1,30 @@
+(ns tau.api.playlists
+ (:require
+ [clojure.java.data :as j]
+ [ring.util.codec :refer [url-decode]]
+ [tau.api.items :as items])
+ (:import
+ org.schabi.newpipe.extractor.playlist.PlaylistInfo
+ org.schabi.newpipe.extractor.Page
+ org.schabi.newpipe.extractor.NewPipe))
+
+(defn get-playlist
+ ([url]
+ (let [service (NewPipe/getServiceByUrl (url-decode url))
+ info (PlaylistInfo/getInfo service (url-decode url))]
+ {:id (.getId info)
+ :name (.getName info)
+ :playlist-type (j/from-java (.getPlaylistType info))
+ :thumbnail-url (.getThumbnailUrl info)
+ :banner-url (.getBannerUrl info)
+ :uploader-name (.getUploaderName info)
+ :uploader-url (.getUploaderUrl info)
+ :uploader-avatar (.getUploaderAvatarUrl info)
+ :stream-count (.getStreamCount info)
+ :next-page (j/from-java (.getNextPage info))
+ :related-streams (items/get-items (.getRelatedItems info))}))
+ ([url page-url]
+ (let [service (NewPipe/getServiceByUrl (url-decode url))
+ info (PlaylistInfo/getMoreItems service url (Page. (url-decode page-url)))]
+ {:next-page (j/from-java (.getNextPage info))
+ :related-streams (items/get-items (.getItems info))})))
diff --git a/src/backend/tau/api/result.clj b/src/backend/tau/api/result.clj
deleted file mode 100644
index 901ea51..0000000
--- a/src/backend/tau/api/result.clj
+++ /dev/null
@@ -1,59 +0,0 @@
-(ns tau.api.result)
-
-(defrecord PlaylistResult
- [name thumbnail-url url upload-author stream-count])
-
-(defrecord ChannelResult
- [name description verified? thumbnail-url url
- subscriber-count stream-count])
-
-(defrecord StreamResult
- [name url thumbnail-url upload-author upload-url
- upload-avatar upload-date short-description
- duration view-count uploaded verified?])
-
-(defn get-stream-result
- [stream]
- (map->StreamResult
- {:url (.getUrl stream)
- :name (.getName stream)
- :thumbnail-url (.getThumbnailUrl stream)
- :upload-author (.getUploaderName stream)
- :upload-url (.getUploaderUrl stream)
- :upload-avatar (.getUploaderAvatarUrl stream)
- :upload-date (.getTextualUploadDate stream)
- :short-description (.getShortDescription stream)
- :duration (.getDuration stream)
- :view-count (.getViewCount stream)
- :uploaded (if (.getUploadDate stream)
- (.. stream (getUploadDate) (offsetDateTime) (toInstant) (toEpochMilli))
- false)
- :verified? (.isUploaderVerified stream)}))
-
-(defn get-channel-result
- [channel]
- (map->ChannelResult
- {:url (.getUrl channel)
- :name (.getName channel)
- :thumbnail-url (.getThumbnailUrl channel)
- :description (.getDescription channel)
- :subscriber-count (.getSubscriberCount channel)
- :stream-count (.getStreamCount channel)
- :verified? (.isVerified channel)}))
-
-(defn get-playlist-result
- [playlist]
- (map->PlaylistResult
- {:url (.getUrl playlist)
- :name (.getName playlist)
- :thumbnail-url (.getThumbnailUrl playlist)
- :upload-author (.getUploaderName playlist)
- :stream-count (.getStreamCount playlist)}))
-
-(defn get-results
- [items]
- (map #(case (.name (.getInfoType %))
- "STREAM" (get-stream-result %)
- "CHANNEL" (get-channel-result %)
- "PLAYLIST" (get-playlist-result %))
- items))
diff --git a/src/backend/tau/api/search.clj b/src/backend/tau/api/search.clj
deleted file mode 100644
index 9f3132f..0000000
--- a/src/backend/tau/api/search.clj
+++ /dev/null
@@ -1,39 +0,0 @@
-(ns tau.api.search
- (:require
- [clojure.java.data :as j]
- [ring.util.codec :refer [url-encode url-decode]]
- [tau.api.result :as result])
- (:import
- org.schabi.newpipe.extractor.search.SearchInfo
- org.schabi.newpipe.extractor.InfoItem
- org.schabi.newpipe.extractor.NewPipe
- org.schabi.newpipe.extractor.Page))
-
-(defrecord SearchResult
- [items next-page search-suggestion corrected-search?])
-
-(defrecord SearchResultPage
- [items next-page])
-
-(defn get-info
- ([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)]
- (map->SearchResult
- {:items (result/get-results (.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))]
- (map->SearchResultPage
- {:items (result/get-results (.getItems info))
- :next-page (j/from-java (.getNextPage info))}))))
diff --git a/src/backend/tau/api/service.clj b/src/backend/tau/api/service.clj
deleted file mode 100644
index b9f0e1d..0000000
--- a/src/backend/tau/api/service.clj
+++ /dev/null
@@ -1,25 +0,0 @@
-(ns tau.api.service
- (:require
- [clojure.java.data :as j]
- [tau.api.kiosk :as kiosk])
- (:import
- org.schabi.newpipe.extractor.NewPipe
- org.schabi.newpipe.extractor.kiosk.KioskList
- org.schabi.newpipe.extractor.StreamingService))
-
-(defrecord Service
- [id info base-url kiosk-list])
-
-(defn get-info
- [service]
- (map->Service
- {:id (.getServiceId service)
- :info (j/from-java (.getServiceInfo service))
- :base-url (.getBaseUrl service)
- ;; :kiosk-list (map #(kiosk/get-info % (.getServiceId service))
- ;; (.getAvailableKiosks (.getKioskList service)))
- }))
-
-(defn get-services
- []
- (map #(get-info %) (NewPipe/getServices)))
diff --git a/src/backend/tau/api/services.clj b/src/backend/tau/api/services.clj
new file mode 100644
index 0000000..8b9638f
--- /dev/null
+++ b/src/backend/tau/api/services.clj
@@ -0,0 +1,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)))
diff --git a/src/backend/tau/api/stream.clj b/src/backend/tau/api/stream.clj
deleted file mode 100644
index d935a6f..0000000
--- a/src/backend/tau/api/stream.clj
+++ /dev/null
@@ -1,45 +0,0 @@
-(ns tau.api.stream
- (:require
- [clojure.java.data :as j]
- [ring.util.codec :refer [url-decode]]
- [tau.api.result :as result])
- (:import
- org.schabi.newpipe.extractor.stream.StreamInfo
- org.schabi.newpipe.extractor.NewPipe
- org.schabi.newpipe.extractor.localization.DateWrapper
- java.time.Instant))
-
-(defrecord Stream
- [name description upload-date
- upload-author upload-url upload-avatar
- thumbnail-url service-id duration view-count like-count
- dislike-count subscriber-count upload-verified? hls-url
- dash-mpd-url category tags audio-streams video-streams
- related-streams])
-
-(defn get-info
- [url]
- (let [info (StreamInfo/getInfo (url-decode url))]
- (map->Stream
- {:name (.getName info)
- :url (.getUrl info)
- :description (.. info (getDescription) (getContent))
- :upload-date (.getTextualUploadDate info)
- :upload-author (.getUploaderName info)
- :upload-url (.getUploaderUrl info)
- :upload-avatar (.getUploaderAvatarUrl info)
- :upload-verified? (.isUploaderVerified info)
- :service-id (.getServiceId info)
- :thumbnail-url (.getThumbnailUrl info)
- :duration (.getDuration info)
- :tags (.getTags info)
- :category (.getCategory info)
- :view-count (.getViewCount info)
- :like-count (if (= (.getLikeCount info) -1) nil (.getLikeCount info))
- :dislike-count (if (= (.getDislikeCount info) -1) nil (.getDislikeCount info))
- :subscriber-count (if (= (.getUploaderSubscriberCount info) -1) nil (.getUploaderSubscriberCount info))
- :audio-streams (j/from-java (.getAudioStreams info))
- :video-streams (j/from-java (.getVideoStreams info))
- :hls-url (.getHlsUrl info)
- :dash-mpd-url (.getDashMpdUrl info)
- :related-streams (result/get-results (.getRelatedStreams info))})))
diff --git a/src/backend/tau/api/streams.clj b/src/backend/tau/api/streams.clj
new file mode 100644
index 0000000..46d8008
--- /dev/null
+++ b/src/backend/tau/api/streams.clj
@@ -0,0 +1,36 @@
+(ns tau.api.streams
+ (:require
+ [clojure.java.data :as j]
+ [ring.util.codec :refer [url-decode]]
+ [tau.api.items :as items])
+ (:import
+ org.schabi.newpipe.extractor.stream.StreamInfo
+ org.schabi.newpipe.extractor.NewPipe
+ org.schabi.newpipe.extractor.localization.DateWrapper
+ java.time.Instant))
+
+(defn get-stream
+ [url]
+ (let [info (StreamInfo/getInfo (url-decode url))]
+ {:name (.getName info)
+ :url (.getUrl info)
+ :description (.. info (getDescription) (getContent))
+ :upload-date (.getTextualUploadDate info)
+ :uploader-author (.getUploaderName info)
+ :uploader-url (.getUploaderUrl info)
+ :uploader-avatar (.getUploaderAvatarUrl info)
+ :uploader-verified? (.isUploaderVerified info)
+ :service-id (.getServiceId info)
+ :thumbnail-url (.getThumbnailUrl info)
+ :duration (.getDuration info)
+ :tags (.getTags info)
+ :category (.getCategory info)
+ :view-count (.getViewCount info)
+ :like-count (when-not (= (.getLikeCount info) -1) (.getLikeCount info))
+ :dislike-count (when-not (= (.getDislikeCount info) -1) (.getDislikeCount info))
+ :subscriber-count (when-not (= (.getUploaderSubscriberCount info) -1) (.getUploaderSubscriberCount info))
+ :audio-streams (j/from-java (.getAudioStreams info))
+ :video-streams (j/from-java (.getVideoStreams info))
+ :hls-url (.getHlsUrl info)
+ :dash-mpd-url (.getDashMpdUrl info)
+ :related-streams (items/get-items (.getRelatedStreams info))}))
diff --git a/src/backend/tau/handler.clj b/src/backend/tau/handler.clj
index 3dc5219..49b7114 100644
--- a/src/backend/tau/handler.clj
+++ b/src/backend/tau/handler.clj
@@ -3,13 +3,11 @@
[clojure.string :as str]
[hiccup.page :as hiccup]
[ring.util.response :refer [response]]
- [tau.api.stream :as stream]
- [tau.api.search :as search]
- [tau.api.channel :as channel]
- [tau.api.playlist :as playlist]
- [tau.api.comment :as comment]
- [tau.api.kiosk :as kiosk]
- [tau.api.service :as service]))
+ [tau.api.streams :as streams]
+ [tau.api.channels :as channels]
+ [tau.api.playlists :as playlists]
+ [tau.api.comments :as comments]
+ [tau.api.services :as services]))
(defn index
[_]
@@ -32,40 +30,41 @@
{:strs [contentFilters sortFilter nextPage]} (:query-params req)
content-filters (and contentFilters (str/split contentFilters #","))]
(response (if nextPage
- (search/get-info service-id q contentFilters sortFilter nextPage)
- (search/get-info service-id q contentFilters sortFilter)))))
+ (services/search service-id q contentFilters sortFilter nextPage)
+ (services/search service-id q contentFilters sortFilter)))))
(defn channel
[{{:keys [url]} :path-params {:strs [nextPage]} :query-params}]
(response (if nextPage
- (channel/get-info url nextPage)
- (channel/get-info url))))
+ (channels/get-channel url nextPage)
+ (channels/get-channel url))))
(defn playlist
[{{:keys [url]} :path-params {:strs [nextPage]} :query-params}]
(response (if nextPage
- (playlist/get-info url nextPage)
- (playlist/get-info url))))
+ (playlists/get-playlist url nextPage)
+ (playlists/get-playlist url))))
(defn comments
[{{:keys [url]} :path-params {:strs [nextPage]} :query-params}]
(response (if nextPage
- (comment/get-info url nextPage)
- (comment/get-info url))))
+ (comments/get-comment url nextPage)
+ (comments/get-comment url))))
(defn services
[_]
- (response (service/get-services)))
+ (response (services/get-services)))
(defn kiosks
[{{{:keys [service-id]} :path} :parameters}]
- (response (kiosk/get-kiosks service-id)))
+ (response (services/get-kiosks service-id)))
(defn kiosk
[{{{:keys [kiosk-id service-id]} :path} :parameters {:strs [nextPage]} :query-params}]
- (response (if nextPage
- (kiosk/get-info kiosk-id service-id nextPage)
- (kiosk/get-info kiosk-id service-id))))
+ (response (cond
+ (and kiosk-id service-id nextPage) (services/get-kiosk kiosk-id service-id nextPage)
+ (and kiosk-id service-id) (services/get-kiosk kiosk-id service-id)
+ :else (services/get-kiosk service-id))))
(defn stream [{{:keys [url]} :path-params}]
- (response (stream/get-info url)))
+ (response (streams/get-stream url)))
diff --git a/src/backend/tau/router.clj b/src/backend/tau/router.clj
index d6573e9..5bab278 100644
--- a/src/backend/tau/router.clj
+++ b/src/backend/tau/router.clj
@@ -27,14 +27,17 @@
:parameters {:path {:service-id int?}
:query {:q string?}}
:handler handler/search}}]
- ["/:service-id/kiosks"
- ["" {:get {:coercion reitit.coercion.malli/coercion
- :parameters {:path {:service-id int?}}
- :handler handler/kiosks}}]
- ["/:kiosk-id"
+ ["/:service-id"
+ ["/default-kiosk" {:get {:coercion reitit.coercion.malli/coercion
+ :parameters {:path {:service-id int?}}
+ :handler handler/kiosk}}]
+ ["/kiosks"
["" {:get {:coercion reitit.coercion.malli/coercion
- :parameters {:path {:service-id int? :kiosk-id string?}}
- :handler handler/kiosk}}]]]]
+ :parameters {:path {:service-id int?}}
+ :handler handler/kiosks}}]
+ ["/:kiosk-id" {:get {:coercion reitit.coercion.malli/coercion
+ :parameters {:path {:service-id int? :kiosk-id string?}}
+ :handler handler/kiosk}}]]]]
["/streams/:url" {:get handler/stream}]
["/channels/:url" {:get handler/channel}]
["/playlists/:url" {:get handler/playlist}]