aboutsummaryrefslogtreecommitdiff
path: root/src/backend/tau/api/result.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/result.clj
parentd4d81cdfbb96c8fc359053a99d19adc9c4cc8ff8 (diff)
feat: Abstract away result items into standalone namespace
Diffstat (limited to 'src/backend/tau/api/result.clj')
-rw-r--r--src/backend/tau/api/result.clj59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/backend/tau/api/result.clj b/src/backend/tau/api/result.clj
new file mode 100644
index 0000000..901ea51
--- /dev/null
+++ b/src/backend/tau/api/result.clj
@@ -0,0 +1,59 @@
+(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))