diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudCommentsInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudCommentsInfoItemExtractor.java index 79b27f1b2d..a97cd95a3e 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudCommentsInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudCommentsInfoItemExtractor.java @@ -20,20 +20,30 @@ public class SoundcloudCommentsInfoItemExtractor implements CommentsInfoItemExtractor { public static final String USER = "user"; public static final String BODY = "body"; + public static final String USER_PERMALINK = "permalink"; private final JsonObject json; private final int index; private final JsonObject item; private final String url; + private final JsonObject superComment; private int replyCount = CommentsInfoItem.UNKNOWN_REPLY_COUNT; private Page repliesPage = null; - public SoundcloudCommentsInfoItemExtractor(final JsonObject json, final int index, final JsonObject item, final String url) { + public SoundcloudCommentsInfoItemExtractor(final JsonObject json, final int index, + final JsonObject item, final String url, + @Nullable final JsonObject superComment) { this.json = json; this.index = index; this.item = item; this.url = url; + this.superComment = superComment; + } + + public SoundcloudCommentsInfoItemExtractor(final JsonObject json, final int index, + final JsonObject item, final String url) { + this(json, index, item, url, null); } @Override @@ -43,12 +53,27 @@ public String getCommentId() { @Override public Description getCommentText() { - return new Description(item.getString(BODY), Description.PLAIN_TEXT); + String commentContent = item.getString(BODY); + if (superComment == null) { + return new Description(commentContent, Description.PLAIN_TEXT); + } + // This comment is a reply to another comment. + // Therefore, the comment starts with the mention of the original comment's author. + // The account is automatically linked by the SoundCloud web UI. + // We need to do this manually. + final JsonObject user = superComment.getObject("user"); + final String link = "" + + "@" + user.getString("full_name") + ""; + commentContent = commentContent + .replace("@" + user.getString(USER_PERMALINK), link) + .replace("@" + superComment.getInt("user_id"), link); + + return new Description(commentContent, Description.HTML); } @Override public String getUploaderName() { - return item.getObject(USER).getString("username"); + return item.getObject(USER).getString("full_name"); } @Override @@ -105,7 +130,7 @@ public Page getReplies() { ServiceList.SoundCloud.getServiceId()); final JsonArray jsonArray = new JsonArray(); // Replies start with the mention of the user who created the original comment. - final String mention = "@" + item.getObject(USER).getString("permalink"); + final String mention = "@" + item.getObject(USER).getString(USER_PERMALINK); // Loop through all comments which come after the original comment to find its replies. final JsonArray allItems = json.getArray(SoundcloudCommentsExtractor.COLLECTION); for (int i = index + 1; i < allItems.size(); i++) { @@ -114,7 +139,8 @@ public Page getReplies() { if (commentContent.startsWith(mention)) { replies.add(comment); jsonArray.add(comment); - collector.commit(new SoundcloudCommentsInfoItemExtractor(json, i, comment, url)); + collector.commit(new SoundcloudCommentsInfoItemExtractor( + json, i, comment, url, item)); } else if (!commentContent.startsWith("@") || replies.isEmpty()) { // Only the comments directly after the original comment // starting with the mention of the comment's creator