feat(youtube/comments): support creator replies
This commit is contained in:
parent
0821f09114
commit
34b05a0dda
|
@ -31,6 +31,7 @@ public class CommentsInfoItem extends InfoItem {
|
||||||
@Nullable
|
@Nullable
|
||||||
private Page replies;
|
private Page replies;
|
||||||
private boolean isChannelOwner;
|
private boolean isChannelOwner;
|
||||||
|
private boolean creatorReply;
|
||||||
|
|
||||||
public static final int NO_LIKE_COUNT = -1;
|
public static final int NO_LIKE_COUNT = -1;
|
||||||
public static final int NO_STREAM_POSITION = -1;
|
public static final int NO_STREAM_POSITION = -1;
|
||||||
|
@ -182,4 +183,13 @@ public class CommentsInfoItem extends InfoItem {
|
||||||
return isChannelOwner;
|
return isChannelOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setCreatorReply(final boolean creatorReply) {
|
||||||
|
this.creatorReply = creatorReply;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasCreatorReply() {
|
||||||
|
return creatorReply;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,4 +141,11 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor {
|
||||||
default boolean isChannelOwner() throws ParsingException {
|
default boolean isChannelOwner() throws ParsingException {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the comment was replied to by the creator.
|
||||||
|
*/
|
||||||
|
default boolean hasCreatorReply() throws ParsingException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,13 @@ public final class CommentsInfoItemsCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
resultItem.setCreatorReply(extractor.hasCreatorReply());
|
||||||
|
} catch (final Exception e) {
|
||||||
|
addError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return resultItem;
|
return resultItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -283,4 +283,16 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract
|
||||||
return getCommentRenderer().getBoolean("authorIsChannelOwner");
|
return getCommentRenderer().getBoolean("authorIsChannelOwner");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasCreatorReply() throws ParsingException {
|
||||||
|
try {
|
||||||
|
final JsonObject commentRepliesRenderer = JsonUtils.getObject(json,
|
||||||
|
"replies.commentRepliesRenderer");
|
||||||
|
return commentRepliesRenderer.has("viewRepliesCreatorThumbnail");
|
||||||
|
} catch (final Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -395,6 +395,49 @@ public class YoutubeCommentsExtractorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class CreatorReply {
|
||||||
|
private final static String url = "https://www.youtube.com/watch?v=bem4adjGKjE";
|
||||||
|
private static YoutubeCommentsExtractor extractor;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void setUp() throws Exception {
|
||||||
|
YoutubeTestsUtils.ensureStateless();
|
||||||
|
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "creatorReply"));
|
||||||
|
extractor = (YoutubeCommentsExtractor) YouTube
|
||||||
|
.getCommentsExtractor(url);
|
||||||
|
extractor.fetchPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetCommentsAllData() throws IOException, ExtractionException {
|
||||||
|
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
|
||||||
|
|
||||||
|
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
|
||||||
|
|
||||||
|
boolean creatorReply = false;
|
||||||
|
|
||||||
|
for (final CommentsInfoItem c : comments.getItems()) {
|
||||||
|
assertFalse(Utils.isBlank(c.getUploaderUrl()));
|
||||||
|
assertFalse(Utils.isBlank(c.getUploaderName()));
|
||||||
|
YoutubeTestsUtils.testImages(c.getUploaderAvatars());
|
||||||
|
assertFalse(Utils.isBlank(c.getCommentId()));
|
||||||
|
assertFalse(Utils.isBlank(c.getName()));
|
||||||
|
assertFalse(Utils.isBlank(c.getTextualUploadDate()));
|
||||||
|
assertNotNull(c.getUploadDate());
|
||||||
|
YoutubeTestsUtils.testImages(c.getThumbnails());
|
||||||
|
assertFalse(Utils.isBlank(c.getUrl()));
|
||||||
|
assertTrue(c.getLikeCount() >= 0);
|
||||||
|
assertFalse(Utils.isBlank(c.getCommentText().getContent()));
|
||||||
|
if (c.hasCreatorReply()) {
|
||||||
|
creatorReply = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(creatorReply, "No comments was replied to by creator");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class FormattingTest {
|
public static class FormattingTest {
|
||||||
|
|
||||||
private final static String url = "https://www.youtube.com/watch?v=zYpyS2HaZHM";
|
private final static String url = "https://www.youtube.com/watch?v=zYpyS2HaZHM";
|
||||||
|
|
Loading…
Reference in New Issue