Skip to content

Commit d358ba1

Browse files
committed
Improve PeertubeCommentsInfoItemExtractor constructor
1 parent aff3e79 commit d358ba1

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsExtractor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public InfoItemsPage<CommentsInfoItem> getInitialPage()
5454
}
5555
}
5656

57-
boolean isReply() throws ParsingException {
57+
private boolean isReply() throws ParsingException {
5858
if (isReply == null) {
5959
if (getOriginalUrl().contains("/videos/watch/")) {
6060
isReply = false;
@@ -73,7 +73,8 @@ private void collectCommentsFrom(@Nonnull final CommentsInfoItemsCollector colle
7373
if (c instanceof JsonObject) {
7474
final JsonObject item = (JsonObject) c;
7575
if (!item.getBoolean(IS_DELETED)) {
76-
collector.commit(new PeertubeCommentsInfoItemExtractor(item, null, this));
76+
collector.commit(new PeertubeCommentsInfoItemExtractor(
77+
item, null, getUrl(), getBaseUrl(), isReply()));
7778
}
7879
}
7980
}
@@ -89,7 +90,8 @@ private void collectRepliesFrom(@Nonnull final CommentsInfoItemsCollector collec
8990
final JsonObject item = content.getObject("comment");
9091
final JsonArray children = content.getArray(CHILDREN);
9192
if (!item.getBoolean(IS_DELETED)) {
92-
collector.commit(new PeertubeCommentsInfoItemExtractor(item, children, this));
93+
collector.commit(new PeertubeCommentsInfoItemExtractor(
94+
item, children, getUrl(), getBaseUrl(), isReply()));
9395
}
9496
}
9597
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
3131
private final String url;
3232
@Nonnull
3333
private final String baseUrl;
34-
@Nonnull
35-
private final PeertubeCommentsExtractor superCommentExtractor;
34+
private final boolean isReply;
3635

3736
private Integer replyCount;
3837

3938
public PeertubeCommentsInfoItemExtractor(@Nonnull final JsonObject item,
4039
@Nullable final JsonArray children,
41-
@Nonnull final PeertubeCommentsExtractor extractor)
42-
throws ParsingException {
40+
@Nonnull final String url,
41+
@Nonnull final String baseUrl,
42+
final boolean isReply) {
4343
this.item = item;
4444
this.children = children;
45-
this.url = extractor.getUrl();
46-
this.baseUrl = extractor.getBaseUrl();
47-
this.superCommentExtractor = extractor;
45+
this.url = url;
46+
this.baseUrl = baseUrl;
47+
this.isReply = isReply;
4848
}
4949

5050
@Override
@@ -130,7 +130,7 @@ public Page getReplies() throws ParsingException {
130130
}
131131
final String threadId = JsonUtils.getNumber(item, "threadId").toString();
132132
final String repliesUrl = url + "/" + threadId;
133-
if (superCommentExtractor.isReply() && children != null && !children.isEmpty()) {
133+
if (isReply && children != null && !children.isEmpty()) {
134134
// Nested replies are already included in the original thread's request.
135135
// Wrap the replies into a JsonObject, because the original thread's request body
136136
// is also structured like a JsonObject.

0 commit comments

Comments
 (0)