[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; private int replyCount;
@Nullable @Nullable
private Page replies; private Page replies;
private boolean creatorReply; private boolean isChannelOwner;
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;
@ -174,12 +174,12 @@ public class CommentsInfoItem extends InfoItem {
return this.replies; return this.replies;
} }
public void setCreatorReply(final boolean creatorReply) { public void setChannelOwner(final boolean channelOwner) {
this.creatorReply = creatorReply; this.isChannelOwner = channelOwner;
} }
public boolean hasCreatorReply() { public boolean isChannelOwner() {
return creatorReply; 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; return false;
} }
} }

View File

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

View File

@ -279,14 +279,8 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract
} }
@Override @Override
public boolean hasCreatorReply() throws ParsingException { public boolean isChannelOwner() throws ParsingException {
try { return getCommentRenderer().getBoolean("authorIsChannelOwner");
final JsonObject commentRepliesRenderer = JsonUtils.getObject(json,
"replies.commentRepliesRenderer");
return commentRepliesRenderer.has("viewRepliesCreatorThumbnail");
} catch (final Exception e) {
return false;
}
} }
} }

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 final static String url = "https://www.youtube.com/watch?v=bem4adjGKjE";
private static YoutubeCommentsExtractor extractor; private static YoutubeCommentsExtractor extractor;
@BeforeAll @BeforeAll
public static void setUp() throws Exception { public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless(); YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "creatorReply")); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "channelOwner"));
extractor = (YoutubeCommentsExtractor) YouTube extractor = (YoutubeCommentsExtractor) YouTube
.getCommentsExtractor(url); .getCommentsExtractor(url);
extractor.fetchPage(); extractor.fetchPage();
@ -371,7 +371,7 @@ public class YoutubeCommentsExtractorTest {
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors()); DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
boolean creatorReply = false; boolean channelOwner = false;
for (final CommentsInfoItem c : comments.getItems()) { for (final CommentsInfoItem c : comments.getItems()) {
assertFalse(Utils.isBlank(c.getUploaderUrl())); assertFalse(Utils.isBlank(c.getUploaderUrl()));
@ -385,11 +385,11 @@ public class YoutubeCommentsExtractorTest {
assertFalse(Utils.isBlank(c.getUrl())); assertFalse(Utils.isBlank(c.getUrl()));
assertTrue(c.getLikeCount() >= 0); assertTrue(c.getLikeCount() >= 0);
assertFalse(Utils.isBlank(c.getCommentText().getContent())); assertFalse(Utils.isBlank(c.getCommentText().getContent()));
if (c.hasCreatorReply()) { if (c.isChannelOwner()) {
creatorReply = true; channelOwner = true;
} }
} }
assertTrue(creatorReply, "No comments was replied to by creator"); assertTrue(channelOwner, "No comments was made by the channel owner");
} }
} }