[YouTube] Add channel owner to comments

This commit is contained in:
FineFindus 2023-10-08 11:36:13 +02:00
parent f9846352ea
commit c1784a4bdb
No known key found for this signature in database
GPG Key ID: 64873EE210FF8E6B
5 changed files with 16 additions and 22 deletions

View File

@ -30,7 +30,7 @@ public class CommentsInfoItem extends InfoItem {
private int replyCount;
@Nullable
private Page replies;
private boolean creatorReply;
private boolean isChannelOwner;
public static final int NO_LIKE_COUNT = -1;
public static final int NO_STREAM_POSITION = -1;
@ -174,12 +174,12 @@ public class CommentsInfoItem extends InfoItem {
return this.replies;
}
public void setCreatorReply(final boolean creatorReply) {
this.creatorReply = creatorReply;
public void setChannelOwner(final boolean channelOwner) {
this.isChannelOwner = channelOwner;
}
public boolean hasCreatorReply() {
return creatorReply;
public boolean isChannelOwner() {
return isChannelOwner;
}
}

View File

@ -136,9 +136,9 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor {
}
/**
* Whether the comment was replied to by the creator.
* Whether the comment was made by the channel owner.
*/
default boolean hasCreatorReply() throws ParsingException {
default boolean isChannelOwner() throws ParsingException {
return false;
}
}

View File

@ -102,7 +102,7 @@ public final class CommentsInfoItemsCollector
}
try {
resultItem.setCreatorReply(extractor.hasCreatorReply());
resultItem.setChannelOwner(extractor.isChannelOwner());
} catch (final Exception e) {
addError(e);
}

View File

@ -279,14 +279,8 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract
}
@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;
}
public boolean isChannelOwner() throws ParsingException {
return getCommentRenderer().getBoolean("authorIsChannelOwner");
}
}

View File

@ -352,14 +352,14 @@ public class YoutubeCommentsExtractorTest {
}
}
public static class CreatorReply {
public static class ChannelOwnerTest {
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"));
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "channelOwner"));
extractor = (YoutubeCommentsExtractor) YouTube
.getCommentsExtractor(url);
extractor.fetchPage();
@ -371,7 +371,7 @@ public class YoutubeCommentsExtractorTest {
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
boolean creatorReply = false;
boolean channelOwner = false;
for (final CommentsInfoItem c : comments.getItems()) {
assertFalse(Utils.isBlank(c.getUploaderUrl()));
@ -385,11 +385,11 @@ public class YoutubeCommentsExtractorTest {
assertFalse(Utils.isBlank(c.getUrl()));
assertTrue(c.getLikeCount() >= 0);
assertFalse(Utils.isBlank(c.getCommentText().getContent()));
if (c.hasCreatorReply()) {
creatorReply = true;
if (c.isChannelOwner()) {
channelOwner = true;
}
}
assertTrue(creatorReply, "No comments was replied to by creator");
assertTrue(channelOwner, "No comments was made by the channel owner");
}
}