aboutsummaryrefslogtreecommitdiff
path: root/src/backend/tau/api/stream.clj
diff options
context:
space:
mode:
authorMiguel Ángel Moreno <mail@migalmoreno.com>2022-12-26 21:46:15 +0100
committerMiguel Ángel Moreno <mail@migalmoreno.com>2022-12-26 21:46:15 +0100
commit9361d6444548748445db1548d0e3a6291d802bd3 (patch)
tree4de1a845bb94d11ce8568e692b615c2e20ab72bd /src/backend/tau/api/stream.clj
parentd4d81cdfbb96c8fc359053a99d19adc9c4cc8ff8 (diff)
feat: Abstract away result items into standalone namespace
Diffstat (limited to 'src/backend/tau/api/stream.clj')
-rw-r--r--src/backend/tau/api/stream.clj44
1 files changed, 6 insertions, 38 deletions
diff --git a/src/backend/tau/api/stream.clj b/src/backend/tau/api/stream.clj
index 63ab183..d935a6f 100644
--- a/src/backend/tau/api/stream.clj
+++ b/src/backend/tau/api/stream.clj
@@ -1,9 +1,8 @@
(ns tau.api.stream
(:require
- [tau.api.playlist :as playlist]
- [tau.api.channel :as channel]
[clojure.java.data :as j]
- [ring.util.codec :refer [url-decode]])
+ [ring.util.codec :refer [url-decode]]
+ [tau.api.result :as result])
(:import
org.schabi.newpipe.extractor.stream.StreamInfo
org.schabi.newpipe.extractor.NewPipe
@@ -18,37 +17,6 @@
dash-mpd-url category tags audio-streams video-streams
related-streams])
-(defrecord StreamResult
- [name url thumbnail-url upload-author upload-url
- upload-avatar upload-date short-description
- duration view-count uploaded verified?])
-
-(defn get-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-results
- [items]
- (map #(case (.name (.getInfoType %))
- "STREAM" (get-result %)
- "CHANNEL" (channel/get-result %)
- "PLAYLIST" (playlist/get-result %))
- items))
-
(defn get-info
[url]
(let [info (StreamInfo/getInfo (url-decode url))]
@@ -67,11 +35,11 @@
:tags (.getTags info)
:category (.getCategory info)
:view-count (.getViewCount info)
- :like-count (.getLikeCount info)
- :dislike-count (.getDislikeCount info)
- :subscriber-count (.getUploaderSubscriberCount 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 (get-results (.getRelatedStreams info))})))
+ :related-streams (result/get-results (.getRelatedStreams info))})))