Skip to content

Commit 665c69b

Browse files
authored
Merge pull request #310 from B0pol/soundcloudComments
Add support for soundcloud comments
2 parents 4086715 + bc13e0c commit 665c69b

57 files changed

Lines changed: 386 additions & 174 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
import org.schabi.newpipe.extractor.ListExtractor;
44
import org.schabi.newpipe.extractor.StreamingService;
5+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
56
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
67

8+
import javax.annotation.Nonnull;
9+
710
public abstract class CommentsExtractor extends ListExtractor<CommentsInfoItem> {
811

912
public CommentsExtractor(StreamingService service, ListLinkHandler uiHandler) {
1013
super(service, uiHandler);
1114
// TODO Auto-generated constructor stub
1215
}
1316

17+
@Nonnull
18+
@Override
19+
public String getName() throws ParsingException {
20+
return "Comments";
21+
}
1422
}

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

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ public class CommentsInfoItem extends InfoItem {
99

1010
private String commentId;
1111
private String commentText;
12-
private String authorName;
13-
private String authorThumbnail;
14-
private String authorEndpoint;
15-
private String textualPublishedTime;
16-
@Nullable private DateWrapper publishedTime;
12+
private String uploaderName;
13+
private String uploaderAvatarUrl;
14+
private String uploaderUrl;
15+
private String textualUploadDate;
16+
@Nullable
17+
private DateWrapper uploadDate;
1718
private int likeCount;
1819

1920
public CommentsInfoItem(int serviceId, String url, String name) {
@@ -36,45 +37,45 @@ public void setCommentText(String commentText) {
3637
this.commentText = commentText;
3738
}
3839

39-
public String getAuthorName() {
40-
return authorName;
40+
public String getUploaderName() {
41+
return uploaderName;
4142
}
4243

43-
public void setAuthorName(String authorName) {
44-
this.authorName = authorName;
44+
public void setUploaderName(String uploaderName) {
45+
this.uploaderName = uploaderName;
4546
}
4647

47-
public String getAuthorThumbnail() {
48-
return authorThumbnail;
48+
public String getUploaderAvatarUrl() {
49+
return uploaderAvatarUrl;
4950
}
5051

51-
public void setAuthorThumbnail(String authorThumbnail) {
52-
this.authorThumbnail = authorThumbnail;
52+
public void setUploaderAvatarUrl(String uploaderAvatarUrl) {
53+
this.uploaderAvatarUrl = uploaderAvatarUrl;
5354
}
5455

55-
public String getAuthorEndpoint() {
56-
return authorEndpoint;
56+
public String getUploaderUrl() {
57+
return uploaderUrl;
5758
}
5859

59-
public void setAuthorEndpoint(String authorEndpoint) {
60-
this.authorEndpoint = authorEndpoint;
60+
public void setUploaderUrl(String uploaderUrl) {
61+
this.uploaderUrl = uploaderUrl;
6162
}
6263

63-
public String getTextualPublishedTime() {
64-
return textualPublishedTime;
64+
public String getTextualUploadDate() {
65+
return textualUploadDate;
6566
}
6667

67-
public void setTextualPublishedTime(String textualPublishedTime) {
68-
this.textualPublishedTime = textualPublishedTime;
68+
public void setTextualUploadDate(String textualUploadDate) {
69+
this.textualUploadDate = textualUploadDate;
6970
}
7071

7172
@Nullable
72-
public DateWrapper getPublishedTime() {
73-
return publishedTime;
73+
public DateWrapper getUploadDate() {
74+
return uploadDate;
7475
}
7576

76-
public void setPublishedTime(@Nullable DateWrapper publishedTime) {
77-
this.publishedTime = publishedTime;
77+
public void setUploadDate(@Nullable DateWrapper uploadDate) {
78+
this.uploadDate = uploadDate;
7879
}
7980

8081
public int getLikeCount() {

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

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,41 @@
33
import org.schabi.newpipe.extractor.InfoItemExtractor;
44
import org.schabi.newpipe.extractor.exceptions.ParsingException;
55
import org.schabi.newpipe.extractor.localization.DateWrapper;
6+
import org.schabi.newpipe.extractor.stream.StreamExtractor;
67

78
import javax.annotation.Nullable;
89

910
public interface CommentsInfoItemExtractor extends InfoItemExtractor {
10-
String getCommentId() throws ParsingException;
11+
12+
/**
13+
* Return the like count of the comment, or -1 if it's unavailable
14+
* @see StreamExtractor#getLikeCount()
15+
*/
16+
int getLikeCount() throws ParsingException;
17+
18+
/**
19+
* The text of the comment
20+
*/
1121
String getCommentText() throws ParsingException;
12-
String getAuthorName() throws ParsingException;
13-
String getAuthorThumbnail() throws ParsingException;
14-
String getAuthorEndpoint() throws ParsingException;
15-
String getTextualPublishedTime() throws ParsingException;
22+
23+
/**
24+
* The upload date given by the service, unmodified
25+
* @see StreamExtractor#getTextualUploadDate()
26+
*/
27+
String getTextualUploadDate() throws ParsingException;
28+
29+
/**
30+
* The upload date wrapped with DateWrapper class
31+
* @see StreamExtractor#getUploadDate()
32+
*/
1633
@Nullable
17-
DateWrapper getPublishedTime() throws ParsingException;
18-
int getLikeCount() throws ParsingException;
34+
DateWrapper getUploadDate() throws ParsingException;
35+
36+
String getCommentId() throws ParsingException;
37+
38+
String getUploaderUrl() throws ParsingException;
39+
40+
String getUploaderName() throws ParsingException;
41+
42+
String getUploaderAvatarUrl() throws ParsingException;
1943
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@ public CommentsInfoItem extract(CommentsInfoItemExtractor extractor) throws Pars
3535
addError(e);
3636
}
3737
try {
38-
resultItem.setAuthorName(extractor.getAuthorName());
38+
resultItem.setUploaderName(extractor.getUploaderName());
3939
} catch (Exception e) {
4040
addError(e);
4141
}
4242
try {
43-
resultItem.setAuthorThumbnail(extractor.getAuthorThumbnail());
43+
resultItem.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
4444
} catch (Exception e) {
4545
addError(e);
4646
}
4747
try {
48-
resultItem.setAuthorEndpoint(extractor.getAuthorEndpoint());
48+
resultItem.setUploaderUrl(extractor.getUploaderUrl());
4949
} catch (Exception e) {
5050
addError(e);
5151
}
5252
try {
53-
resultItem.setTextualPublishedTime(extractor.getTextualPublishedTime());
53+
resultItem.setTextualUploadDate(extractor.getTextualUploadDate());
5454
} catch (Exception e) {
5555
addError(e);
5656
}
5757
try {
58-
resultItem.setPublishedTime(extractor.getPublishedTime());
58+
resultItem.setUploadDate(extractor.getUploadDate());
5959
} catch (Exception e) {
6060
addError(e);
6161
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsExtractor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ public PeertubeCommentsExtractor(StreamingService service, ListLinkHandler uiHan
3333
super(service, uiHandler);
3434
}
3535

36-
@Override
37-
public String getName() throws ParsingException {
38-
return "Comments";
39-
}
40-
4136
@Override
4237
public InfoItemsPage<CommentsInfoItem> getInitialPage() throws IOException, ExtractionException {
4338
super.fetchPage();

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public String getName() throws ParsingException {
4545
}
4646

4747
@Override
48-
public String getTextualPublishedTime() throws ParsingException {
48+
public String getTextualUploadDate() throws ParsingException {
4949
return JsonUtils.getString(item, "createdAt");
5050
}
5151

5252
@Override
53-
public DateWrapper getPublishedTime() throws ParsingException {
54-
String textualUploadDate = getTextualPublishedTime();
53+
public DateWrapper getUploadDate() throws ParsingException {
54+
String textualUploadDate = getTextualUploadDate();
5555
return new DateWrapper(PeertubeParsingHelper.parseDateFrom(textualUploadDate));
5656
}
5757

@@ -78,7 +78,7 @@ public String getCommentId() throws ParsingException {
7878
}
7979

8080
@Override
81-
public String getAuthorThumbnail() throws ParsingException {
81+
public String getUploaderAvatarUrl() throws ParsingException {
8282
String value;
8383
try {
8484
value = JsonUtils.getString(item, "account.avatar.path");
@@ -89,12 +89,12 @@ public String getAuthorThumbnail() throws ParsingException {
8989
}
9090

9191
@Override
92-
public String getAuthorName() throws ParsingException {
92+
public String getUploaderName() throws ParsingException {
9393
return JsonUtils.getString(item, "account.name") + "@" + JsonUtils.getString(item, "account.host");
9494
}
9595

9696
@Override
97-
public String getAuthorEndpoint() throws ParsingException {
97+
public String getUploaderUrl() throws ParsingException {
9898
String name = JsonUtils.getString(item, "account.name");
9999
String host = JsonUtils.getString(item, "account.host");
100100
return ServiceList.PeerTube.getChannelLHFactory().fromId("accounts/" + name + "@" + host, baseUrl).getUrl();

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1616
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1717
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
18+
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudChannelInfoItemExtractor;
19+
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudStreamExtractor;
20+
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudStreamInfoItemExtractor;
1821
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
1922
import org.schabi.newpipe.extractor.utils.Parser;
2023
import org.schabi.newpipe.extractor.utils.Parser.RegexException;
@@ -86,10 +89,12 @@ static boolean checkIfHardcodedClientIdIsValid() {
8689
}
8790
}
8891

89-
static Calendar parseDate(String textualUploadDate) throws ParsingException {
92+
public static Calendar parseDateFrom(String textualUploadDate) throws ParsingException {
9093
Date date;
9194
try {
92-
date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse(textualUploadDate);
95+
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
96+
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
97+
date = sdf.parse(textualUploadDate);
9398
} catch (ParseException e1) {
9499
try {
95100
date = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss +0000").parse(textualUploadDate);
@@ -256,13 +261,13 @@ public static String getStreamsFromApi(StreamInfoItemsCollector collector, Strin
256261
}
257262

258263
@Nonnull
259-
static String getUploaderUrl(JsonObject object) {
264+
public static String getUploaderUrl(JsonObject object) {
260265
String url = object.getObject("user").getString("permalink_url", EMPTY_STRING);
261266
return replaceHttpWithHttps(url);
262267
}
263268

264269
@Nonnull
265-
static String getAvatarUrl(JsonObject object) {
270+
public static String getAvatarUrl(JsonObject object) {
266271
String url = object.getObject("user").getString("avatar_url", EMPTY_STRING);
267272
return replaceHttpWithHttps(url);
268273
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudService.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@
1010
import org.schabi.newpipe.extractor.localization.ContentCountry;
1111
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
1212
import org.schabi.newpipe.extractor.search.SearchExtractor;
13+
import org.schabi.newpipe.extractor.services.soundcloud.extractors.*;
14+
import org.schabi.newpipe.extractor.services.soundcloud.linkHandler.*;
1315
import org.schabi.newpipe.extractor.stream.StreamExtractor;
1416
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
1517

1618
import java.util.List;
1719

18-
import static java.util.Collections.singletonList;
20+
import static java.util.Arrays.asList;
1921
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.AUDIO;
22+
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.COMMENTS;
2023

2124
public class SoundcloudService extends StreamingService {
2225

2326
public SoundcloudService(int id) {
24-
super(id, "SoundCloud", singletonList(AUDIO));
27+
super(id, "SoundCloud", asList(AUDIO, COMMENTS));
2528
}
2629

2730
@Override
@@ -117,13 +120,13 @@ public SubscriptionExtractor getSubscriptionExtractor() {
117120

118121
@Override
119122
public ListLinkHandlerFactory getCommentsLHFactory() {
120-
return null;
123+
return SoundcloudCommentsLinkHandlerFactory.getInstance();
121124
}
122125

123126
@Override
124127
public CommentsExtractor getCommentsExtractor(ListLinkHandler linkHandler)
125128
throws ExtractionException {
126-
return null;
129+
return new SoundcloudCommentsExtractor(this, linkHandler);
127130
}
128131

129132
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractor.java renamed to extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelExtractor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.schabi.newpipe.extractor.services.soundcloud;
1+
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
22

33
import com.grack.nanojson.JsonArray;
44
import com.grack.nanojson.JsonObject;
@@ -10,6 +10,7 @@
1010
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1111
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1212
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
13+
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
1314
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1415
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
1516

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelInfoItemExtractor.java renamed to extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelInfoItemExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.schabi.newpipe.extractor.services.soundcloud;
1+
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
22

33
import com.grack.nanojson.JsonObject;
44
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;

0 commit comments

Comments
 (0)