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/comments.clj | |
parent | 6382ec24c5bbbf93ced1e587103a52b3a63e6045 (diff) |
feat(backend): Remove records and simplify API
Diffstat (limited to 'src/backend/tau/api/comments.clj')
-rw-r--r-- | src/backend/tau/api/comments.clj | 37 |
1 files changed, 37 insertions, 0 deletions
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}))) |