mirror of
https://github.com/TeamNewPipe/NewPipeExtractor
synced 2024-12-02 06:50:17 +01:00
Merge pull request #625 from TeamNewPipe/commentsStreamPosition
Add streamPosition for comments
This commit is contained in:
commit
a27575021d
@ -20,6 +20,10 @@ public class CommentsInfoItem extends InfoItem {
|
||||
private String textualLikeCount;
|
||||
private boolean heartedByUploader;
|
||||
private boolean pinned;
|
||||
private int streamPosition;
|
||||
|
||||
public static final int NO_LIKE_COUNT = -1;
|
||||
public static final int NO_STREAM_POSITION = -1;
|
||||
|
||||
public CommentsInfoItem(int serviceId, String url, String name) {
|
||||
super(InfoType.COMMENT, serviceId, url, name);
|
||||
@ -82,6 +86,10 @@ public class CommentsInfoItem extends InfoItem {
|
||||
this.uploadDate = uploadDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the comment's like count
|
||||
* or {@link CommentsInfoItem#NO_LIKE_COUNT} if it is unavailable
|
||||
*/
|
||||
public int getLikeCount() {
|
||||
return likeCount;
|
||||
}
|
||||
@ -121,4 +129,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;
|
||||
}
|
||||
}
|
||||
|
@ -12,15 +12,20 @@ import javax.annotation.Nullable;
|
||||
public interface CommentsInfoItemExtractor extends InfoItemExtractor {
|
||||
|
||||
/**
|
||||
* Return the like count of the comment, or -1 if it's unavailable
|
||||
* Return the like count of the comment,
|
||||
* or {@link CommentsInfoItem#NO_LIKE_COUNT} if it is unavailable.
|
||||
*
|
||||
* <br>
|
||||
*
|
||||
* NOTE: Currently only implemented for YT {@link YoutubeCommentsInfoItemExtractor#getLikeCount()}
|
||||
* with limitations (only approximate like count is returned)
|
||||
*
|
||||
* @see StreamExtractor#getLikeCount()
|
||||
* @return the comment's like count
|
||||
* or {@link CommentsInfoItem#NO_LIKE_COUNT} if it is unavailable
|
||||
*/
|
||||
default int getLikeCount() throws ParsingException {
|
||||
return -1;
|
||||
return CommentsInfoItem.NO_LIKE_COUNT;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,4 +99,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;
|
||||
}
|
||||
}
|
||||
|
@ -87,6 +87,12 @@ public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoI
|
||||
addError(e);
|
||||
}
|
||||
|
||||
try {
|
||||
resultItem.setStreamPosition(extractor.getStreamPosition());
|
||||
} catch (Exception e) {
|
||||
addError(e);
|
||||
}
|
||||
|
||||
return resultItem;
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,11 @@ public class SoundcloudCommentsInfoItemExtractor implements CommentsInfoItemExtr
|
||||
return json.getObject("user").getBoolean("verified");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStreamPosition() throws ParsingException {
|
||||
return json.getInt("timestamp") / 1000; // convert milliseconds to seconds
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUploaderUrl() {
|
||||
return json.getObject("user").getString("permalink_url");
|
||||
@ -65,7 +70,7 @@ public class SoundcloudCommentsInfoItemExtractor implements CommentsInfoItemExtr
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() throws ParsingException {
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract
|
||||
return json.has("pinnedCommentBadge");
|
||||
}
|
||||
|
||||
public boolean isUploaderVerified() throws ParsingException {
|
||||
public boolean isUploaderVerified() {
|
||||
// impossible to get this information from the mobile layout
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user