Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YouTube] Add channel owner to comments #1114

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class CommentsInfoItem extends InfoItem {
private int replyCount;
@Nullable
private Page replies;
private boolean isChannelOwner;
private boolean creatorReply;

public static final int NO_LIKE_COUNT = -1;
Expand Down Expand Up @@ -174,6 +175,15 @@ public Page getReplies() {
return this.replies;
}

public void setChannelOwner(final boolean channelOwner) {
this.isChannelOwner = channelOwner;
}

public boolean isChannelOwner() {
return isChannelOwner;
}


public void setCreatorReply(final boolean creatorReply) {
this.creatorReply = creatorReply;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ default Page getReplies() throws ParsingException {
return null;
}

/**
* Whether the comment was made by the channel owner.
*/
default boolean isChannelOwner() throws ParsingException {
return false;
}

/**
* Whether the comment was replied to by the creator.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ public CommentsInfoItem extract(final CommentsInfoItemExtractor extractor)
addError(e);
}

try {
resultItem.setChannelOwner(extractor.isChannelOwner());
} catch (final Exception e) {
addError(e);
}


try {
resultItem.setCreatorReply(extractor.hasCreatorReply());
} catch (final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ public Page getReplies() {
}
}

@Override
public boolean isChannelOwner() throws ParsingException {
return getCommentRenderer().getBoolean("authorIsChannelOwner");
}


@Override
public boolean hasCreatorReply() throws ParsingException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,49 @@ public void testCommentsCount() throws IOException, ExtractionException {
}
}

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 + "channelOwner"));
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 channelOwner = 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.isChannelOwner()) {
channelOwner = true;
}
}
assertTrue(channelOwner, "No comments was made by the channel owner");

}
}


public static class CreatorReply {
private final static String url = "https://www.youtube.com/watch?v=bem4adjGKjE";
private static YoutubeCommentsExtractor extractor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"request": {
"httpMethod": "GET",
"url": "https://www.youtube.com/sw.js",
"headers": {
"Referer": [
"https://www.youtube.com"
],
"Origin": [
"https://www.youtube.com"
],
"Accept-Language": [
"en-GB, en;q\u003d0.9"
]
},
"localization": {
"languageCode": "en",
"countryCode": "GB"
}
},
"response": {
"responseCode": 200,
"responseMessage": "",
"responseHeaders": {
"access-control-allow-credentials": [
"true"
],
"access-control-allow-origin": [
"https://www.youtube.com"
],
"alt-svc": [
"h3\u003d\":443\"; ma\u003d2592000,h3-29\u003d\":443\"; ma\u003d2592000"
],
"cache-control": [
"private, max-age\u003d0"
],
"content-type": [
"text/javascript; charset\u003dutf-8"
],
"cross-origin-opener-policy": [
"same-origin; report-to\u003d\"youtube_main\""
],
"date": [
"Mon, 09 Oct 2023 09:27:33 GMT"
],
"expires": [
"Mon, 09 Oct 2023 09:27:33 GMT"
],
"origin-trial": [
"AvC9UlR6RDk2crliDsFl66RWLnTbHrDbp+DiY6AYz/PNQ4G4tdUTjrHYr2sghbkhGQAVxb7jaPTHpEVBz0uzQwkAAAB4eyJvcmlnaW4iOiJodHRwczovL3lvdXR1YmUuY29tOjQ0MyIsImZlYXR1cmUiOiJXZWJWaWV3WFJlcXVlc3RlZFdpdGhEZXByZWNhdGlvbiIsImV4cGlyeSI6MTcxOTUzMjc5OSwiaXNTdWJkb21haW4iOnRydWV9"
],
"p3p": [
"CP\u003d\"This is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl\u003den-GB for more info.\""
],
"permissions-policy": [
"ch-ua-arch\u003d*, ch-ua-bitness\u003d*, ch-ua-full-version\u003d*, ch-ua-full-version-list\u003d*, ch-ua-model\u003d*, ch-ua-wow64\u003d*, ch-ua-form-factor\u003d*, ch-ua-platform\u003d*, ch-ua-platform-version\u003d*"
],
"report-to": [
"{\"group\":\"youtube_main\",\"max_age\":2592000,\"endpoints\":[{\"url\":\"https://csp.withgoogle.com/csp/report-to/youtube_main\"}]}"
],
"server": [
"ESF"
],
"set-cookie": [
"YSC\u003deXlTV75IWtE; Domain\u003d.youtube.com; Path\u003d/; Secure; HttpOnly; SameSite\u003dnone",
"VISITOR_INFO1_LIVE\u003d; Domain\u003d.youtube.com; Expires\u003dTue, 12-Jan-2021 09:27:33 GMT; Path\u003d/; Secure; HttpOnly; SameSite\u003dnone",
"CONSENT\u003dPENDING+344; expires\u003dWed, 08-Oct-2025 09:27:33 GMT; path\u003d/; domain\u003d.youtube.com; Secure"
],
"strict-transport-security": [
"max-age\u003d31536000"
],
"x-content-type-options": [
"nosniff"
],
"x-frame-options": [
"SAMEORIGIN"
],
"x-xss-protection": [
"0"
]
},
"responseBody": "\n self.addEventListener(\u0027install\u0027, event \u003d\u003e {\n event.waitUntil(self.skipWaiting());\n });\n self.addEventListener(\u0027activate\u0027, event \u003d\u003e {\n event.waitUntil(\n self.clients.claim().then(() \u003d\u003e self.registration.unregister()));\n });\n ",
"latestUrl": "https://www.youtube.com/sw.js"
}
}

Large diffs are not rendered by default.

Loading