2020-04-10 14:48:11 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
|
|
|
|
|
|
|
|
import com.grack.nanojson.JsonObject;
|
2022-07-25 18:58:20 +02:00
|
|
|
import org.schabi.newpipe.extractor.Image;
|
2020-04-10 14:48:11 +02:00
|
|
|
import org.schabi.newpipe.extractor.comments.CommentsInfoItemExtractor;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
|
|
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
2022-11-28 01:22:10 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.Description;
|
2020-04-10 14:48:11 +02:00
|
|
|
|
2022-07-25 18:58:20 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2020-04-10 14:48:11 +02:00
|
|
|
import javax.annotation.Nullable;
|
2022-07-25 18:58:20 +02:00
|
|
|
import java.util.List;
|
2021-01-22 01:44:58 +01:00
|
|
|
import java.util.Objects;
|
2020-04-10 14:48:11 +02:00
|
|
|
|
2022-07-25 18:58:20 +02:00
|
|
|
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.getAllImagesFromArtworkOrAvatarUrl;
|
|
|
|
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.parseDateFrom;
|
|
|
|
|
2020-04-10 14:48:11 +02:00
|
|
|
public class SoundcloudCommentsInfoItemExtractor implements CommentsInfoItemExtractor {
|
2021-05-15 17:51:43 +02:00
|
|
|
private final JsonObject json;
|
|
|
|
private final String url;
|
2020-04-10 14:48:11 +02:00
|
|
|
|
2021-05-15 17:51:43 +02:00
|
|
|
public SoundcloudCommentsInfoItemExtractor(final JsonObject json, final String url) {
|
2020-04-10 14:48:11 +02:00
|
|
|
this.json = json;
|
|
|
|
this.url = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-06-13 20:25:38 +02:00
|
|
|
public String getCommentId() {
|
|
|
|
return Objects.toString(json.getLong("id"), null);
|
2020-04-10 14:48:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-11-28 01:22:10 +01:00
|
|
|
public Description getCommentText() {
|
|
|
|
return new Description(json.getString("body"), Description.PLAIN_TEXT);
|
2020-04-10 14:48:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-06-13 20:25:38 +02:00
|
|
|
public String getUploaderName() {
|
2020-04-10 14:48:11 +02:00
|
|
|
return json.getObject("user").getString("username");
|
|
|
|
}
|
|
|
|
|
2022-07-25 18:58:20 +02:00
|
|
|
@Nonnull
|
2020-04-10 14:48:11 +02:00
|
|
|
@Override
|
2022-07-25 18:58:20 +02:00
|
|
|
public List<Image> getUploaderAvatars() {
|
|
|
|
return getAllImagesFromArtworkOrAvatarUrl(json.getObject("user").getString("avatar_url"));
|
2020-04-10 14:48:11 +02:00
|
|
|
}
|
|
|
|
|
2021-01-22 01:44:58 +01:00
|
|
|
@Override
|
|
|
|
public boolean isUploaderVerified() throws ParsingException {
|
|
|
|
return json.getObject("user").getBoolean("verified");
|
|
|
|
}
|
|
|
|
|
2021-06-06 11:18:23 +02:00
|
|
|
@Override
|
2022-07-25 18:58:20 +02:00
|
|
|
public int getStreamPosition() {
|
2021-06-06 11:18:23 +02:00
|
|
|
return json.getInt("timestamp") / 1000; // convert milliseconds to seconds
|
|
|
|
}
|
|
|
|
|
2020-04-10 14:48:11 +02:00
|
|
|
@Override
|
2020-06-13 20:25:38 +02:00
|
|
|
public String getUploaderUrl() {
|
2020-04-10 14:48:11 +02:00
|
|
|
return json.getObject("user").getString("permalink_url");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-06-13 20:25:38 +02:00
|
|
|
public String getTextualUploadDate() {
|
2020-04-10 14:48:11 +02:00
|
|
|
return json.getString("created_at");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
2020-04-21 19:49:17 +02:00
|
|
|
public DateWrapper getUploadDate() throws ParsingException {
|
2022-07-25 18:58:20 +02:00
|
|
|
return new DateWrapper(parseDateFrom(getTextualUploadDate()));
|
2020-04-10 14:48:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() throws ParsingException {
|
|
|
|
return json.getObject("user").getString("permalink");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-06-06 11:18:23 +02:00
|
|
|
public String getUrl() {
|
2020-04-10 14:48:11 +02:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2022-07-25 18:58:20 +02:00
|
|
|
@Nonnull
|
2020-04-10 14:48:11 +02:00
|
|
|
@Override
|
2022-07-25 18:58:20 +02:00
|
|
|
public List<Image> getThumbnails() {
|
|
|
|
return getAllImagesFromArtworkOrAvatarUrl(json.getObject("user").getString("avatar_url"));
|
2020-04-10 14:48:11 +02:00
|
|
|
}
|
|
|
|
}
|