130 lines
4.1 KiB
Java
130 lines
4.1 KiB
Java
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
|
|
|
|
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
|
|
|
|
import com.grack.nanojson.JsonObject;
|
|
import com.grack.nanojson.JsonParser;
|
|
import com.grack.nanojson.JsonParserException;
|
|
|
|
import org.schabi.newpipe.extractor.StreamingService;
|
|
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
import org.schabi.newpipe.extractor.linkhandler.ChannelTabs;
|
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
|
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
|
|
import org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudChannelTabLinkHandlerFactory;
|
|
|
|
import java.io.IOException;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
public class SoundcloudChannelExtractor extends ChannelExtractor {
|
|
private String userId;
|
|
private JsonObject user;
|
|
private static final String USERS_ENDPOINT = SOUNDCLOUD_API_V2_URL + "users/";
|
|
|
|
public SoundcloudChannelExtractor(final StreamingService service,
|
|
final ListLinkHandler linkHandler) {
|
|
super(service, linkHandler);
|
|
}
|
|
|
|
@Override
|
|
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException,
|
|
ExtractionException {
|
|
|
|
userId = getLinkHandler().getId();
|
|
final String apiUrl = USERS_ENDPOINT + userId + "?client_id="
|
|
+ SoundcloudParsingHelper.clientId();
|
|
|
|
final String response = downloader.get(apiUrl, getExtractorLocalization()).responseBody();
|
|
try {
|
|
user = JsonParser.object().from(response);
|
|
} catch (final JsonParserException e) {
|
|
throw new ParsingException("Could not parse json response", e);
|
|
}
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public String getId() {
|
|
return userId;
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public String getName() {
|
|
return user.getString("username");
|
|
}
|
|
|
|
@Override
|
|
public String getAvatarUrl() {
|
|
return user.getString("avatar_url");
|
|
}
|
|
|
|
@Override
|
|
public String getBannerUrl() {
|
|
return user.getObject("visuals").getArray("visuals").getObject(0)
|
|
.getString("visual_url");
|
|
}
|
|
|
|
@Override
|
|
public String getFeedUrl() {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public long getSubscriberCount() {
|
|
return user.getLong("followers_count", 0);
|
|
}
|
|
|
|
@Override
|
|
public String getDescription() {
|
|
return user.getString("description", "");
|
|
}
|
|
|
|
@Override
|
|
public String getParentChannelName() {
|
|
return "";
|
|
}
|
|
|
|
@Override
|
|
public String getParentChannelUrl() {
|
|
return "";
|
|
}
|
|
|
|
@Override
|
|
public String getParentChannelAvatarUrl() {
|
|
return "";
|
|
}
|
|
|
|
@Override
|
|
public boolean isVerified() throws ParsingException {
|
|
return user.getBoolean("verified");
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public List<ListLinkHandler> getTabs() throws ParsingException {
|
|
final String urlTracks = getUrl()
|
|
+ SoundcloudChannelTabLinkHandlerFactory.getUrlSuffix(ChannelTabs.TRACKS);
|
|
final String urlPlaylists = getUrl()
|
|
+ SoundcloudChannelTabLinkHandlerFactory.getUrlSuffix(ChannelTabs.PLAYLISTS);
|
|
final String urlAlbums = getUrl()
|
|
+ SoundcloudChannelTabLinkHandlerFactory.getUrlSuffix(ChannelTabs.ALBUMS);
|
|
|
|
return Arrays.asList(
|
|
new ListLinkHandler(urlTracks, urlTracks, getId(),
|
|
Collections.singletonList(ChannelTabs.TRACKS), ""),
|
|
new ListLinkHandler(urlPlaylists, urlPlaylists, getId(),
|
|
Collections.singletonList(ChannelTabs.PLAYLISTS), ""),
|
|
new ListLinkHandler(urlAlbums, urlAlbums, getId(),
|
|
Collections.singletonList(ChannelTabs.ALBUMS), "")
|
|
);
|
|
}
|
|
}
|