aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorMiguel Ángel Moreno <mail@migalmoreno.com>2022-12-31 11:57:10 +0100
committerMiguel Ángel Moreno <mail@migalmoreno.com>2022-12-31 11:57:10 +0100
commit5fc4b8d6edb031cd4a65f788f15832eb659fd2bf (patch)
tree263a62b3ac8fb410797ca3eec0a5e2fb29148157 /src/backend
parenta4da13d078f254621383f455e91c4ce9ff8c9c4e (diff)
feat: Add support for comment replies
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/tau/api/comments.clj24
-rw-r--r--src/backend/tau/handler.clj4
2 files changed, 18 insertions, 10 deletions
diff --git a/src/backend/tau/api/comments.clj b/src/backend/tau/api/comments.clj
index 477c72d..c0891ea 100644
--- a/src/backend/tau/api/comments.clj
+++ b/src/backend/tau/api/comments.clj
@@ -5,33 +5,41 @@
(:import
org.schabi.newpipe.extractor.NewPipe
org.schabi.newpipe.extractor.Page
+ org.schabi.newpipe.extractor.ListExtractor
org.schabi.newpipe.extractor.comments.CommentsInfoItem
org.schabi.newpipe.extractor.comments.CommentsInfo))
(defn get-comment-item
- [item]
+ [item extractor]
{: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)
+ :upload-date (.getTextualUploadDate item)
:like-count (when-not (= (.getLikeCount item) -1) (.getLikeCount item))
+ :reply-count (when-not (= (.getReplyCount item) -1) (.getReplyCount item))
:hearted-by-uploader? (.isHeartedByUploader item)
:pinned? (.isPinned item)
+ :stream-position (when-not (= (.getStreamPosition item) -1) (.getStreamPosition item))
:replies (when (.getReplies item)
- (j/from-java (.getReplies item)))})
+ (if extractor
+ (let [comments-page (.getPage extractor (.getReplies item))]
+ {:next-page (when (.hasNextPage comments-page) (j/from-java (.getNextPage comments-page)))
+ :items (map #(get-comment-item % extractor) (.getItems comments-page))})
+ (j/from-java (.getReplies item))))})
-(defn get-comment
+(defn get-comments
([url]
- (let [info (CommentsInfo/getInfo (url-decode url))]
- {:comments (map get-comment-item (.getRelatedItems info))
+ (let [info (CommentsInfo/getInfo (url-decode url))
+ extractor (.getCommentsExtractor info)]
+ {:comments (map #(get-comment-item % extractor) (.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))
+ info (CommentsInfo/getMoreItems service (url-decode url) (Page. (url-decode page-url)))]
+ {:comments (map #(get-comment-item % nil) (.getItems info))
:next-page (j/from-java (.getNextPage info))
:disabled? false})))
diff --git a/src/backend/tau/handler.clj b/src/backend/tau/handler.clj
index 49b7114..3ec4469 100644
--- a/src/backend/tau/handler.clj
+++ b/src/backend/tau/handler.clj
@@ -48,8 +48,8 @@
(defn comments
[{{:keys [url]} :path-params {:strs [nextPage]} :query-params}]
(response (if nextPage
- (comments/get-comment url nextPage)
- (comments/get-comment url))))
+ (comments/get-comments url nextPage)
+ (comments/get-comments url))))
(defn services
[_]