From b70c0f93c7b15d58f6c7302d80c4b902cec588dd Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sun, 6 Jun 2021 11:18:23 +0200 Subject: [PATCH] Add streamPosition for comments SoundCloud is the only service which supports adding comments at a specific timestamp in the stream. --- .../extractor/comments/CommentsInfoItem.java | 16 ++++++++++++++++ .../comments/CommentsInfoItemExtractor.java | 8 ++++++++ .../comments/CommentsInfoItemsCollector.java | 6 ++++++ .../SoundcloudCommentsInfoItemExtractor.java | 7 ++++++- .../YoutubeCommentsInfoItemExtractor.java | 2 +- 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItem.java b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItem.java index d27909276..f32710603 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItem.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItem.java @@ -20,6 +20,9 @@ public class CommentsInfoItem extends InfoItem { private String textualLikeCount; private boolean heartedByUploader; private boolean pinned; + private int streamPosition; + + public static final int NO_STREAM_POSITION = -1; public CommentsInfoItem(int serviceId, String url, String name) { super(InfoType.COMMENT, serviceId, url, name); @@ -121,4 +124,17 @@ public class CommentsInfoItem extends InfoItem { public boolean isUploaderVerified() { return uploaderVerified; } + + public void setStreamPosition(final int streamPosition) { + this.streamPosition = streamPosition; + } + + /** + * Get the playback position of the stream to which this comment belongs. + * This is not supported by all services. + * @return the playback position in seconds or {@link #NO_STREAM_POSITION} if not available + */ + public int getStreamPosition() { + return streamPosition; + } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemExtractor.java index 15266e2ee..fb1af7ab0 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemExtractor.java @@ -94,4 +94,12 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor { default boolean isUploaderVerified() throws ParsingException { return false; } + + /** + * The playback position of the stream to which this comment belongs. + * @see CommentsInfoItem#getStreamPosition() + */ + default int getStreamPosition() throws ParsingException { + return CommentsInfoItem.NO_STREAM_POSITION; + } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java index 97d394e10..3dc2d95f1 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java @@ -87,6 +87,12 @@ public class CommentsInfoItemsCollector extends InfoItemsCollector