Skip to content

Commit c1784a4

Browse files
committed
[YouTube] Add channel owner to comments
1 parent f984635 commit c1784a4

5 files changed

Lines changed: 16 additions & 22 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItem.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class CommentsInfoItem extends InfoItem {
3030
private int replyCount;
3131
@Nullable
3232
private Page replies;
33-
private boolean creatorReply;
33+
private boolean isChannelOwner;
3434

3535
public static final int NO_LIKE_COUNT = -1;
3636
public static final int NO_STREAM_POSITION = -1;
@@ -174,12 +174,12 @@ public Page getReplies() {
174174
return this.replies;
175175
}
176176

177-
public void setCreatorReply(final boolean creatorReply) {
178-
this.creatorReply = creatorReply;
177+
public void setChannelOwner(final boolean channelOwner) {
178+
this.isChannelOwner = channelOwner;
179179
}
180180

181-
public boolean hasCreatorReply() {
182-
return creatorReply;
181+
public boolean isChannelOwner() {
182+
return isChannelOwner;
183183
}
184184

185185
}

extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ default Page getReplies() throws ParsingException {
136136
}
137137

138138
/**
139-
* Whether the comment was replied to by the creator.
139+
* Whether the comment was made by the channel owner.
140140
*/
141-
default boolean hasCreatorReply() throws ParsingException {
141+
default boolean isChannelOwner() throws ParsingException {
142142
return false;
143143
}
144144
}

extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public CommentsInfoItem extract(final CommentsInfoItemExtractor extractor)
102102
}
103103

104104
try {
105-
resultItem.setCreatorReply(extractor.hasCreatorReply());
105+
resultItem.setChannelOwner(extractor.isChannelOwner());
106106
} catch (final Exception e) {
107107
addError(e);
108108
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsInfoItemExtractor.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,8 @@ public Page getReplies() {
279279
}
280280

281281
@Override
282-
public boolean hasCreatorReply() throws ParsingException {
283-
try {
284-
final JsonObject commentRepliesRenderer = JsonUtils.getObject(json,
285-
"replies.commentRepliesRenderer");
286-
return commentRepliesRenderer.has("viewRepliesCreatorThumbnail");
287-
} catch (final Exception e) {
288-
return false;
289-
}
282+
public boolean isChannelOwner() throws ParsingException {
283+
return getCommentRenderer().getBoolean("authorIsChannelOwner");
290284
}
291285

292286
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,14 @@ public void testCommentsCount() throws IOException, ExtractionException {
352352
}
353353
}
354354

355-
public static class CreatorReply {
355+
public static class ChannelOwnerTest {
356356
private final static String url = "https://www.youtube.com/watch?v=bem4adjGKjE";
357357
private static YoutubeCommentsExtractor extractor;
358358

359359
@BeforeAll
360360
public static void setUp() throws Exception {
361361
YoutubeTestsUtils.ensureStateless();
362-
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "creatorReply"));
362+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "channelOwner"));
363363
extractor = (YoutubeCommentsExtractor) YouTube
364364
.getCommentsExtractor(url);
365365
extractor.fetchPage();
@@ -371,7 +371,7 @@ void testGetCommentsAllData() throws IOException, ExtractionException {
371371

372372
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
373373

374-
boolean creatorReply = false;
374+
boolean channelOwner = false;
375375

376376
for (final CommentsInfoItem c : comments.getItems()) {
377377
assertFalse(Utils.isBlank(c.getUploaderUrl()));
@@ -385,11 +385,11 @@ void testGetCommentsAllData() throws IOException, ExtractionException {
385385
assertFalse(Utils.isBlank(c.getUrl()));
386386
assertTrue(c.getLikeCount() >= 0);
387387
assertFalse(Utils.isBlank(c.getCommentText().getContent()));
388-
if (c.hasCreatorReply()) {
389-
creatorReply = true;
388+
if (c.isChannelOwner()) {
389+
channelOwner = true;
390390
}
391391
}
392-
assertTrue(creatorReply, "No comments was replied to by creator");
392+
assertTrue(channelOwner, "No comments was made by the channel owner");
393393

394394
}
395395
}

0 commit comments

Comments
 (0)