Skip to content

Commit a275750

Browse files
authored
Merge pull request #625 from TeamNewPipe/commentsStreamPosition
Add streamPosition for comments
2 parents d4186d1 + f7f727d commit a275750

5 files changed

Lines changed: 49 additions & 4 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ 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_LIKE_COUNT = -1;
26+
public static final int NO_STREAM_POSITION = -1;
2327

2428
public CommentsInfoItem(int serviceId, String url, String name) {
2529
super(InfoType.COMMENT, serviceId, url, name);
@@ -82,6 +86,10 @@ public void setUploadDate(@Nullable DateWrapper uploadDate) {
8286
this.uploadDate = uploadDate;
8387
}
8488

89+
/**
90+
* @return the comment's like count
91+
* or {@link CommentsInfoItem#NO_LIKE_COUNT} if it is unavailable
92+
*/
8593
public int getLikeCount() {
8694
return likeCount;
8795
}
@@ -121,4 +129,17 @@ public void setUploaderVerified(boolean uploaderVerified) {
121129
public boolean isUploaderVerified() {
122130
return uploaderVerified;
123131
}
132+
133+
public void setStreamPosition(final int streamPosition) {
134+
this.streamPosition = streamPosition;
135+
}
136+
137+
/**
138+
* Get the playback position of the stream to which this comment belongs.
139+
* This is not supported by all services.
140+
* @return the playback position in seconds or {@link #NO_STREAM_POSITION} if not available
141+
*/
142+
public int getStreamPosition() {
143+
return streamPosition;
144+
}
124145
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@
1212
public interface CommentsInfoItemExtractor extends InfoItemExtractor {
1313

1414
/**
15-
* Return the like count of the comment, or -1 if it's unavailable
15+
* Return the like count of the comment,
16+
* or {@link CommentsInfoItem#NO_LIKE_COUNT} if it is unavailable.
17+
*
1618
* <br>
19+
*
1720
* NOTE: Currently only implemented for YT {@link YoutubeCommentsInfoItemExtractor#getLikeCount()}
1821
* with limitations (only approximate like count is returned)
1922
*
2023
* @see StreamExtractor#getLikeCount()
24+
* @return the comment's like count
25+
* or {@link CommentsInfoItem#NO_LIKE_COUNT} if it is unavailable
2126
*/
2227
default int getLikeCount() throws ParsingException {
23-
return -1;
28+
return CommentsInfoItem.NO_LIKE_COUNT;
2429
}
2530

2631
/**
@@ -94,4 +99,12 @@ default boolean isPinned() throws ParsingException {
9499
default boolean isUploaderVerified() throws ParsingException {
95100
return false;
96101
}
102+
103+
/**
104+
* The playback position of the stream to which this comment belongs.
105+
* @see CommentsInfoItem#getStreamPosition()
106+
*/
107+
default int getStreamPosition() throws ParsingException {
108+
return CommentsInfoItem.NO_STREAM_POSITION;
109+
}
97110
}

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)