Add streamPosition for comments

SoundCloud is the only service which supports adding comments at a specific timestamp in the stream.
This commit is contained in:
TobiGr 2021-06-06 11:18:23 +02:00
parent d4186d100b
commit b70c0f93c7
5 changed files with 37 additions and 2 deletions

View File

@ -20,6 +20,9 @@ public class CommentsInfoItem extends InfoItem {
private String textualLikeCount; private String textualLikeCount;
private boolean heartedByUploader; private boolean heartedByUploader;
private boolean pinned; private boolean pinned;
private int streamPosition;
public static final int NO_STREAM_POSITION = -1;
public CommentsInfoItem(int serviceId, String url, String name) { public CommentsInfoItem(int serviceId, String url, String name) {
super(InfoType.COMMENT, serviceId, url, name); super(InfoType.COMMENT, serviceId, url, name);
@ -121,4 +124,17 @@ public class CommentsInfoItem extends InfoItem {
public boolean isUploaderVerified() { public boolean isUploaderVerified() {
return uploaderVerified; 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;
}
} }

View File

@ -94,4 +94,12 @@ public interface CommentsInfoItemExtractor extends InfoItemExtractor {
default boolean isUploaderVerified() throws ParsingException { default boolean isUploaderVerified() throws ParsingException {
return false; 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;
}
} }

View File

@ -87,6 +87,12 @@ public class CommentsInfoItemsCollector extends InfoItemsCollector<CommentsInfoI
addError(e); addError(e);
} }
try {
resultItem.setStreamPosition(extractor.getStreamPosition());
} catch (Exception e) {
addError(e);
}
return resultItem; return resultItem;
} }

View File

@ -43,6 +43,11 @@ public class SoundcloudCommentsInfoItemExtractor implements CommentsInfoItemExtr
return json.getObject("user").getBoolean("verified"); return json.getObject("user").getBoolean("verified");
} }
@Override
public int getStreamPosition() throws ParsingException {
return json.getInt("timestamp") / 1000; // convert milliseconds to seconds
}
@Override @Override
public String getUploaderUrl() { public String getUploaderUrl() {
return json.getObject("user").getString("permalink_url"); return json.getObject("user").getString("permalink_url");
@ -65,7 +70,7 @@ public class SoundcloudCommentsInfoItemExtractor implements CommentsInfoItemExtr
} }
@Override @Override
public String getUrl() throws ParsingException { public String getUrl() {
return url; return url;
} }

View File

@ -184,7 +184,7 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract
return json.has("pinnedCommentBadge"); return json.has("pinnedCommentBadge");
} }
public boolean isUploaderVerified() throws ParsingException { public boolean isUploaderVerified() {
// impossible to get this information from the mobile layout // impossible to get this information from the mobile layout
return false; return false;
} }