mirror of
https://github.com/TeamNewPipe/NewPipeExtractor
synced 2024-12-01 22:43:27 +01:00
[PeerTube] Implement CommentsInfoItemExtractor.hasCreatorReply()
This commit is contained in:
parent
dd7b2d9798
commit
d49f8411d7
@ -148,4 +148,10 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
||||
}
|
||||
return replyCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCreatorReply() {
|
||||
return item.has("totalRepliesFromVideoAuthor")
|
||||
&& item.getInt("totalRepliesFromVideoAuthor") > 0;
|
||||
}
|
||||
}
|
||||
|
@ -127,26 +127,46 @@ public class PeertubeCommentsExtractorTest {
|
||||
*/
|
||||
public static class NestedComments {
|
||||
private static PeertubeCommentsExtractor extractor;
|
||||
private static InfoItemsPage<CommentsInfoItem> comments = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void setUp() throws Exception {
|
||||
NewPipe.init(DownloaderTestImpl.getInstance());
|
||||
extractor = (PeertubeCommentsExtractor) PeerTube
|
||||
.getCommentsExtractor("https://share.tube/w/vxu4uTstUBAUromWwXGHrq");
|
||||
comments = extractor.getInitialPage();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetComments() throws IOException, ExtractionException {
|
||||
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
|
||||
assertFalse(comments.getItems().isEmpty());
|
||||
final Optional<CommentsInfoItem> nestedCommentHeadOpt =
|
||||
comments.getItems()
|
||||
.stream()
|
||||
.filter(c -> c.getCommentId().equals("9770"))
|
||||
.findFirst();
|
||||
findCommentWithId("9770", comments.getItems());
|
||||
assertTrue(nestedCommentHeadOpt.isPresent());
|
||||
assertTrue(findNestedCommentWithId("9773", nestedCommentHeadOpt.get()), "The nested comment replies were not found");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHasCreatorReply() {
|
||||
assertCreatorReply("9770", true);
|
||||
assertCreatorReply("9852", false);
|
||||
assertCreatorReply("11239", false);
|
||||
}
|
||||
|
||||
private static void assertCreatorReply(final String id, final boolean expected) {
|
||||
final Optional<CommentsInfoItem> comment =
|
||||
findCommentWithId(id, comments.getItems());
|
||||
assertTrue(comment.isPresent());
|
||||
assertEquals(expected, comment.get().hasCreatorReply());
|
||||
}
|
||||
}
|
||||
|
||||
private static Optional<CommentsInfoItem> findCommentWithId(
|
||||
final String id, final List<CommentsInfoItem> comments) {
|
||||
return comments
|
||||
.stream()
|
||||
.filter(c -> c.getCommentId().equals(id))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
private static boolean findNestedCommentWithId(final String id, final CommentsInfoItem comment)
|
||||
|
Loading…
Reference in New Issue
Block a user