Skip to content

Commit b70c0f9

Browse files
committed
Add streamPosition for comments
SoundCloud is the only service which supports adding comments at a specific timestamp in the stream.
1 parent d4186d1 commit b70c0f9

5 files changed

Lines changed: 37 additions & 2 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItem.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class CommentsInfoItem extends InfoItem {
2020
private String textualLikeCount;
2121
private boolean heartedByUploader;
2222
private boolean pinned;
23+
private int streamPosition;
24+
25+
public static final int NO_STREAM_POSITION = -1;
2326

2427
public CommentsInfoItem(int serviceId, String url, String name) {
2528
super(InfoType.COMMENT, serviceId, url, name);
@@ -121,4 +124,17 @@ public void setUploaderVerified(boolean uploaderVerified) {
121124
public boolean isUploaderVerified() {
122125
return uploaderVerified;
123126
}
127+
128+
public void setStreamPosition(final int streamPosition) {
129+
this.streamPosition = streamPosition;
130+
}
131+
132+
/**
133+
* Get the playback position of the stream to which this comment belongs.
134+
* This is not supported by all services.
135+
* @return the playback position in seconds or {@link #NO_STREAM_POSITION} if not available
136+
*/
137+
public int getStreamPosition() {
138+
return streamPosition;
139+
}
124140
}

extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemExtractor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,12 @@ default boolean isPinned() throws ParsingException {
9494
default boolean isUploaderVerified() throws ParsingException {
9595
return false;
9696
}
97+
98+
/**
99+
* The playback position of the stream to which this comment belongs.
100+
* @see CommentsInfoItem#getStreamPosition()
101+
*/
102+
default int getStreamPosition() throws ParsingException {
103+
return CommentsInfoItem.NO_STREAM_POSITION;
104+
}
97105
}

extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ public CommentsInfoItem extract(CommentsInfoItemExtractor extractor) throws Pars
8787
addError(e);
8888
}
8989

90+
try {
91+
resultItem.setStreamPosition(extractor.getStreamPosition());
92+
} catch (Exception e) {
93+
addError(e);
94+
}
95+
9096
return resultItem;
9197
}
9298

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudCommentsInfoItemExtractor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public boolean isUploaderVerified() throws ParsingException {
4343
return json.getObject("user").getBoolean("verified");
4444
}
4545

46+
@Override
47+
public int getStreamPosition() throws ParsingException {
48+
return json.getInt("timestamp") / 1000; // convert milliseconds to seconds
49+
}
50+
4651
@Override
4752
public String getUploaderUrl() {
4853
return json.getObject("user").getString("permalink_url");
@@ -65,7 +70,7 @@ public String getName() throws ParsingException {
6570
}
6671

6772
@Override
68-
public String getUrl() throws ParsingException {
73+
public String getUrl() {
6974
return url;
7075
}
7176

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsInfoItemExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public boolean isPinned() {
184184
return json.has("pinnedCommentBadge");
185185
}
186186

187-
public boolean isUploaderVerified() throws ParsingException {
187+
public boolean isUploaderVerified() {
188188
// impossible to get this information from the mobile layout
189189
return false;
190190
}

0 commit comments

Comments
 (0)