From d358ba1c41c4945cf58634e2a0b2dd67ac7f9b48 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sun, 7 May 2023 22:53:24 +0200 Subject: [PATCH] Improve PeertubeCommentsInfoItemExtractor constructor --- .../extractors/PeertubeCommentsExtractor.java | 8 +++++--- .../PeertubeCommentsInfoItemExtractor.java | 16 ++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsExtractor.java index 220b5a7e5..d7c523bcf 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsExtractor.java @@ -54,7 +54,7 @@ public class PeertubeCommentsExtractor extends CommentsExtractor { } } - boolean isReply() throws ParsingException { + private boolean isReply() throws ParsingException { if (isReply == null) { if (getOriginalUrl().contains("/videos/watch/")) { isReply = false; @@ -73,7 +73,8 @@ public class PeertubeCommentsExtractor extends CommentsExtractor { if (c instanceof JsonObject) { final JsonObject item = (JsonObject) c; if (!item.getBoolean(IS_DELETED)) { - collector.commit(new PeertubeCommentsInfoItemExtractor(item, null, this)); + collector.commit(new PeertubeCommentsInfoItemExtractor( + item, null, getUrl(), getBaseUrl(), isReply())); } } } @@ -89,7 +90,8 @@ public class PeertubeCommentsExtractor extends CommentsExtractor { final JsonObject item = content.getObject("comment"); final JsonArray children = content.getArray(CHILDREN); if (!item.getBoolean(IS_DELETED)) { - collector.commit(new PeertubeCommentsInfoItemExtractor(item, children, this)); + collector.commit(new PeertubeCommentsInfoItemExtractor( + item, children, getUrl(), getBaseUrl(), isReply())); } } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java index 9b1de3dd7..804b23802 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java @@ -31,20 +31,20 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac private final String url; @Nonnull private final String baseUrl; - @Nonnull - private final PeertubeCommentsExtractor superCommentExtractor; + private final boolean isReply; private Integer replyCount; public PeertubeCommentsInfoItemExtractor(@Nonnull final JsonObject item, @Nullable final JsonArray children, - @Nonnull final PeertubeCommentsExtractor extractor) - throws ParsingException { + @Nonnull final String url, + @Nonnull final String baseUrl, + final boolean isReply) { this.item = item; this.children = children; - this.url = extractor.getUrl(); - this.baseUrl = extractor.getBaseUrl(); - this.superCommentExtractor = extractor; + this.url = url; + this.baseUrl = baseUrl; + this.isReply = isReply; } @Override @@ -130,7 +130,7 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac } final String threadId = JsonUtils.getNumber(item, "threadId").toString(); final String repliesUrl = url + "/" + threadId; - if (superCommentExtractor.isReply() && children != null && !children.isEmpty()) { + if (isReply && children != null && !children.isEmpty()) { // Nested replies are already included in the original thread's request. // Wrap the replies into a JsonObject, because the original thread's request body // is also structured like a JsonObject.