aboutsummaryrefslogtreecommitdiff
path: root/src/backend/tau/api/streams.clj
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 /src/backend/tau/api/streams.clj
parent6382ec24c5bbbf93ced1e587103a52b3a63e6045 (diff)
feat(backend): Remove records and simplify API
Diffstat (limited to 'src/backend/tau/api/streams.clj')
-rw-r--r--src/backend/tau/api/streams.clj36
1 files changed, 36 insertions, 0 deletions
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))}))