2020-04-10 10:51:05 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
|
2017-08-04 16:21:45 +02:00
|
|
|
|
2017-08-16 04:40:03 +02:00
|
|
|
import com.grack.nanojson.JsonObject;
|
|
|
|
import com.grack.nanojson.JsonParser;
|
|
|
|
import com.grack.nanojson.JsonParserException;
|
2020-04-15 14:09:46 +02:00
|
|
|
import org.schabi.newpipe.extractor.Page;
|
2017-08-06 22:20:15 +02:00
|
|
|
import org.schabi.newpipe.extractor.StreamingService;
|
2017-08-11 03:23:09 +02:00
|
|
|
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
2020-02-08 23:58:46 +01:00
|
|
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
2017-08-04 16:21:45 +02:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2019-04-28 22:03:16 +02:00
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
2020-04-10 10:51:05 +02:00
|
|
|
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
|
2018-03-01 01:02:43 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
2018-02-24 22:20:50 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
2017-08-04 16:21:45 +02:00
|
|
|
|
2020-05-11 15:25:18 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2021-02-07 22:42:21 +01:00
|
|
|
import java.io.IOException;
|
2020-05-11 15:25:18 +02:00
|
|
|
|
2021-02-07 22:42:21 +01:00
|
|
|
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
|
2020-05-11 11:40:24 +02:00
|
|
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
2020-04-16 16:08:14 +02:00
|
|
|
|
2017-08-04 16:21:45 +02:00
|
|
|
@SuppressWarnings("WeakerAccess")
|
2017-08-11 03:23:09 +02:00
|
|
|
public class SoundcloudChannelExtractor extends ChannelExtractor {
|
2017-08-07 18:12:51 +02:00
|
|
|
private String userId;
|
2017-08-16 04:40:03 +02:00
|
|
|
private JsonObject user;
|
2017-08-04 16:21:45 +02:00
|
|
|
|
2021-05-15 17:51:43 +02:00
|
|
|
public SoundcloudChannelExtractor(final StreamingService service,
|
|
|
|
final ListLinkHandler linkHandler) {
|
2019-04-28 22:03:16 +02:00
|
|
|
super(service, linkHandler);
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
2017-08-04 16:21:45 +02:00
|
|
|
|
2017-08-06 22:20:15 +02:00
|
|
|
@Override
|
2021-05-15 17:51:43 +02:00
|
|
|
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException,
|
|
|
|
ExtractionException {
|
2017-08-04 16:21:45 +02:00
|
|
|
|
2018-09-15 20:12:52 +02:00
|
|
|
userId = getLinkHandler().getId();
|
2020-07-06 20:23:41 +02:00
|
|
|
final String apiUrl = "https://api-v2.soundcloud.com/users/" + userId +
|
2017-08-06 22:20:15 +02:00
|
|
|
"?client_id=" + SoundcloudParsingHelper.clientId();
|
2017-08-04 16:21:45 +02:00
|
|
|
|
2020-07-06 20:23:41 +02:00
|
|
|
final String response = downloader.get(apiUrl, getExtractorLocalization()).responseBody();
|
2017-08-16 04:40:03 +02:00
|
|
|
try {
|
|
|
|
user = JsonParser.object().from(response);
|
2021-05-15 17:51:43 +02:00
|
|
|
} catch (final JsonParserException e) {
|
2017-08-16 04:40:03 +02:00
|
|
|
throw new ParsingException("Could not parse json response", e);
|
|
|
|
}
|
2017-08-04 16:21:45 +02:00
|
|
|
}
|
|
|
|
|
2017-11-25 01:10:04 +01:00
|
|
|
@Nonnull
|
2017-08-04 16:21:45 +02:00
|
|
|
@Override
|
2017-08-11 03:23:09 +02:00
|
|
|
public String getId() {
|
2017-08-07 18:12:51 +02:00
|
|
|
return userId;
|
2017-08-04 16:21:45 +02:00
|
|
|
}
|
|
|
|
|
2017-11-25 01:10:04 +01:00
|
|
|
@Nonnull
|
2017-08-04 16:21:45 +02:00
|
|
|
@Override
|
2017-08-11 03:23:09 +02:00
|
|
|
public String getName() {
|
2017-08-07 18:12:51 +02:00
|
|
|
return user.getString("username");
|
2017-08-04 16:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getAvatarUrl() {
|
2017-08-16 04:40:03 +02:00
|
|
|
return user.getString("avatar_url");
|
2017-08-04 16:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-09-16 10:19:07 +02:00
|
|
|
public String getBannerUrl() {
|
2021-05-15 17:51:43 +02:00
|
|
|
return user.getObject("visuals").getArray("visuals").getObject(0)
|
|
|
|
.getString("visual_url");
|
2017-08-04 16:21:45 +02:00
|
|
|
}
|
|
|
|
|
2017-08-11 03:23:09 +02:00
|
|
|
@Override
|
2017-09-16 10:19:07 +02:00
|
|
|
public String getFeedUrl() {
|
2017-08-11 03:23:09 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-08-04 16:21:45 +02:00
|
|
|
@Override
|
|
|
|
public long getSubscriberCount() {
|
2020-06-13 20:25:38 +02:00
|
|
|
return user.getLong("followers_count", 0);
|
2017-08-04 16:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-26 15:55:27 +01:00
|
|
|
public String getDescription() {
|
2020-04-16 16:08:14 +02:00
|
|
|
return user.getString("description", EMPTY_STRING);
|
2017-08-04 16:21:45 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 22:33:44 +02:00
|
|
|
@Override
|
2020-07-06 20:23:41 +02:00
|
|
|
public String getParentChannelName() {
|
2020-04-13 22:33:44 +02:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-06 20:23:41 +02:00
|
|
|
public String getParentChannelUrl() {
|
2020-04-13 22:33:44 +02:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-06 20:23:41 +02:00
|
|
|
public String getParentChannelAvatarUrl() {
|
2020-04-13 22:33:44 +02:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2021-01-22 01:44:58 +01:00
|
|
|
@Override
|
|
|
|
public boolean isVerified() throws ParsingException {
|
|
|
|
return user.getBoolean("verified");
|
|
|
|
}
|
|
|
|
|
2017-11-25 02:03:30 +01:00
|
|
|
@Nonnull
|
2017-08-04 16:21:45 +02:00
|
|
|
@Override
|
2018-03-11 21:54:41 +01:00
|
|
|
public InfoItemsPage<StreamInfoItem> getInitialPage() throws ExtractionException {
|
2018-02-26 15:55:27 +01:00
|
|
|
try {
|
2021-05-15 17:51:43 +02:00
|
|
|
final StreamInfoItemsCollector streamInfoItemsCollector =
|
|
|
|
new StreamInfoItemsCollector(getServiceId());
|
2017-08-04 16:21:45 +02:00
|
|
|
|
2020-07-06 20:23:41 +02:00
|
|
|
final String apiUrl = "https://api-v2.soundcloud.com/users/" + getId() + "/tracks"
|
2021-05-15 17:51:43 +02:00
|
|
|
+ "?client_id=" + SoundcloudParsingHelper.clientId() + "&limit=20"
|
2018-02-26 15:55:27 +01:00
|
|
|
+ "&linked_partitioning=1";
|
|
|
|
|
2021-05-15 17:51:43 +02:00
|
|
|
final String nextPageUrl = SoundcloudParsingHelper.getStreamsFromApiMinItems(15,
|
|
|
|
streamInfoItemsCollector, apiUrl);
|
2020-04-10 10:25:53 +02:00
|
|
|
|
2020-04-15 14:09:46 +02:00
|
|
|
return new InfoItemsPage<>(streamInfoItemsCollector, new Page(nextPageUrl));
|
2021-05-15 17:51:43 +02:00
|
|
|
} catch (final Exception e) {
|
2018-02-26 15:55:27 +01:00
|
|
|
throw new ExtractionException("Could not get next page", e);
|
|
|
|
}
|
2017-08-04 16:21:45 +02:00
|
|
|
}
|
2017-08-06 22:20:15 +02:00
|
|
|
|
|
|
|
@Override
|
2021-05-15 17:51:43 +02:00
|
|
|
public InfoItemsPage<StreamInfoItem> getPage(final Page page) throws IOException,
|
|
|
|
ExtractionException {
|
2020-05-11 15:25:18 +02:00
|
|
|
if (page == null || isNullOrEmpty(page.getUrl())) {
|
|
|
|
throw new IllegalArgumentException("Page doesn't contain an URL");
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:23:41 +02:00
|
|
|
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
2021-05-15 17:51:43 +02:00
|
|
|
final String nextPageUrl = SoundcloudParsingHelper.getStreamsFromApiMinItems(15, collector,
|
|
|
|
page.getUrl());
|
2017-08-06 22:20:15 +02:00
|
|
|
|
2020-04-15 14:09:46 +02:00
|
|
|
return new InfoItemsPage<>(collector, new Page(nextPageUrl));
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
2017-08-04 16:21:45 +02:00
|
|
|
}
|