diff options
author | Miguel Ángel Moreno <mail@migalmoreno.com> | 2022-12-29 01:53:08 +0100 |
---|---|---|
committer | Miguel Ángel Moreno <mail@migalmoreno.com> | 2022-12-29 01:53:08 +0100 |
commit | dfcc61063822dfb0fe699896da312249e93d5439 (patch) | |
tree | c1dc29de45cfe4ae67f104510dc3c4b6d858aa46 /src/backend/tau/api/items.clj | |
parent | 6382ec24c5bbbf93ced1e587103a52b3a63e6045 (diff) |
feat(backend): Remove records and simplify API
Diffstat (limited to 'src/backend/tau/api/items.clj')
-rw-r--r-- | src/backend/tau/api/items.clj | 47 |
1 files changed, 47 insertions, 0 deletions
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)) |