Skip to content

Commit d49f841

Browse files
committed
[PeerTube] Implement CommentsInfoItemExtractor.hasCreatorReply()
1 parent dd7b2d9 commit d49f841

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,10 @@ public int getReplyCount() throws ParsingException {
148148
}
149149
return replyCount;
150150
}
151+
152+
@Override
153+
public boolean hasCreatorReply() {
154+
return item.has("totalRepliesFromVideoAuthor")
155+
&& item.getInt("totalRepliesFromVideoAuthor") > 0;
156+
}
151157
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsExtractorTest.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,46 @@ void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException {
127127
*/
128128
public static class NestedComments {
129129
private static PeertubeCommentsExtractor extractor;
130+
private static InfoItemsPage<CommentsInfoItem> comments = null;
130131

131132
@BeforeAll
132133
public static void setUp() throws Exception {
133134
NewPipe.init(DownloaderTestImpl.getInstance());
134135
extractor = (PeertubeCommentsExtractor) PeerTube
135136
.getCommentsExtractor("https://share.tube/w/vxu4uTstUBAUromWwXGHrq");
137+
comments = extractor.getInitialPage();
136138
}
137139

138140
@Test
139141
void testGetComments() throws IOException, ExtractionException {
140-
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
141142
assertFalse(comments.getItems().isEmpty());
142143
final Optional<CommentsInfoItem> nestedCommentHeadOpt =
143-
comments.getItems()
144-
.stream()
145-
.filter(c -> c.getCommentId().equals("9770"))
146-
.findFirst();
144+
findCommentWithId("9770", comments.getItems());
147145
assertTrue(nestedCommentHeadOpt.isPresent());
148146
assertTrue(findNestedCommentWithId("9773", nestedCommentHeadOpt.get()), "The nested comment replies were not found");
149147
}
148+
149+
@Test
150+
void testHasCreatorReply() {
151+
assertCreatorReply("9770", true);
152+
assertCreatorReply("9852", false);
153+
assertCreatorReply("11239", false);
154+
}
155+
156+
private static void assertCreatorReply(final String id, final boolean expected) {
157+
final Optional<CommentsInfoItem> comment =
158+
findCommentWithId(id, comments.getItems());
159+
assertTrue(comment.isPresent());
160+
assertEquals(expected, comment.get().hasCreatorReply());
161+
}
162+
}
163+
164+
private static Optional<CommentsInfoItem> findCommentWithId(
165+
final String id, final List<CommentsInfoItem> comments) {
166+
return comments
167+
.stream()
168+
.filter(c -> c.getCommentId().equals(id))
169+
.findFirst();
150170
}
151171

152172
private static boolean findNestedCommentWithId(final String id, final CommentsInfoItem comment)

0 commit comments

Comments
 (0)