Skip to content

Commit

Permalink
[YouTube] Support new A/B tested comments data (#44)
Browse files Browse the repository at this point in the history
* [YouTube] Support new A/B tested comments data

Make getCommentText @nonnull by StyPox

[YouTube] Add channel owner to comments by FineFindus

Co-Authored-By: Audric V. <74829229+audricv@users.noreply.github.com>
Co-Authored-By: Stypox <stypox@pm.me>
Co-Authored-By: FineFindus <63370021+finefindus@users.noreply.github.com>

* Update YoutubeCommentsInfoItemExtractor.java

Co-Authored-By: Audric V. <74829229+audricv@users.noreply.github.com>
Co-Authored-By: Stypox <stypox@pm.me>
Co-Authored-By: FineFindus <63370021+finefindus@users.noreply.github.com>

* Update YoutubeCommentsExtractor.java

Co-Authored-By: Audric V. <74829229+audricv@users.noreply.github.com>
Co-Authored-By: Stypox <stypox@pm.me>
Co-Authored-By: FineFindus <63370021+finefindus@users.noreply.github.com>

* Update YoutubeCommentsEUVMInfoItemExtractor.java

* fix missing import

* fix build

* fix tests

* fix build

* get Uploader name

* Update YoutubeCommentsEUVMInfoItemExtractor.java

---------

Co-authored-by: Audric V. <74829229+audricv@users.noreply.github.com>
Co-authored-by: Stypox <stypox@pm.me>
Co-authored-by: FineFindus <63370021+finefindus@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 3, 2024
1 parent 8787d18 commit e96b5e1
Show file tree
Hide file tree
Showing 24 changed files with 2,914 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.stream.Description;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class CommentsInfoItem extends InfoItem {

private String commentId;
private Description commentText;
@Nonnull
private Description commentText = Description.EMPTY_DESCRIPTION;
private String uploaderName;
private String uploaderAvatarUrl;
private String uploaderUrl;
Expand All @@ -26,6 +28,8 @@ 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;
public static final int NO_STREAM_POSITION = -1;
Expand All @@ -44,11 +48,12 @@ public void setCommentId(final String commentId) {
this.commentId = commentId;
}

@Nonnull
public Description getCommentText() {
return commentText;
}

public void setCommentText(final Description commentText) {
public void setCommentText(@Nonnull final Description commentText) {
this.commentText = commentText;
}

Expand Down Expand Up @@ -167,4 +172,22 @@ public void setReplies(@Nullable final Page replies) {
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;
}

public boolean hasCreatorReply() {
return creatorReply;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.extractor.stream.StreamExtractor;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public interface CommentsInfoItemExtractor extends InfoItemExtractor {
Expand Down Expand Up @@ -42,6 +43,7 @@ default String getTextualLikeCount() throws ParsingException {
/**
* The text of the comment
*/
@Nonnull
default Description getCommentText() throws ParsingException {
return Description.EMPTY_DESCRIPTION;
}
Expand Down Expand Up @@ -130,4 +132,19 @@ default int getReplyCount() throws ParsingException {
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.
*/
@Nullable
default boolean hasCreatorReply() throws ParsingException {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ 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) {
addError(e);
}


return resultItem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.stream.Description;

import javax.annotation.Nonnull;

public class BandcampCommentsInfoItemExtractor implements CommentsInfoItemExtractor {

private final JsonObject review;
Expand All @@ -33,6 +35,7 @@ public String getThumbnailUrl() throws ParsingException {
return getUploaderAvatarUrl();
}

@Nonnull
@Override
public Description getCommentText() throws ParsingException {
return new Description(review.getString("why"), Description.PLAIN_TEXT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public DateWrapper getUploadDate() throws ParsingException {
return new DateWrapper(PeertubeParsingHelper.parseDateFrom(textualUploadDate));
}

@Nonnull
@Override
public Description getCommentText() throws ParsingException {
final String htmlText = JsonUtils.getString(item, "text");
Expand Down Expand Up @@ -160,4 +161,10 @@ public int getReplyCount() throws ParsingException {
}
return replyCount;
}

@Override
public boolean hasCreatorReply() {
return item.has("totalRepliesFromVideoAuthor")
&& item.getInt("totalRepliesFromVideoAuthor") > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
import org.schabi.newpipe.extractor.stream.Description;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Objects;

Expand All @@ -24,6 +25,7 @@ public String getCommentId() {
return Objects.toString(json.getLong("id"), null);
}

@Nonnull
@Override
public Description getCommentText() {
return new Description(json.getString("body"), Description.PLAIN_TEXT);
Expand Down
Loading

0 comments on commit e96b5e1

Please sign in to comment.