mirror of
https://github.com/TeamNewPipe/NewPipeExtractor
synced 2024-12-01 22:43:27 +01:00
[SoundCloud] Apply changes in Extractors
This commit is contained in:
parent
a3a74cd566
commit
31da5beb51
@ -1,11 +1,14 @@
|
||||
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
|
||||
|
||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
|
||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.getAllImagesFromArtworkOrAvatarUrl;
|
||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.getAllImagesFromVisualUrl;
|
||||
|
||||
import com.grack.nanojson.JsonObject;
|
||||
import com.grack.nanojson.JsonParser;
|
||||
import com.grack.nanojson.JsonParserException;
|
||||
|
||||
import org.schabi.newpipe.extractor.Image;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs;
|
||||
@ -59,15 +62,19 @@ public class SoundcloudChannelExtractor extends ChannelExtractor {
|
||||
return user.getString("username");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getAvatarUrl() {
|
||||
return user.getString("avatar_url");
|
||||
public List<Image> getAvatars() {
|
||||
return getAllImagesFromArtworkOrAvatarUrl(user.getString("avatar_url"));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getBannerUrl() {
|
||||
return user.getObject("visuals").getArray("visuals").getObject(0)
|
||||
.getString("visual_url");
|
||||
public List<Image> getBanners() {
|
||||
return getAllImagesFromVisualUrl(user.getObject("visuals")
|
||||
.getArray("visuals")
|
||||
.getObject(0)
|
||||
.getString("visual_url"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -95,9 +102,10 @@ public class SoundcloudChannelExtractor extends ChannelExtractor {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getParentChannelAvatarUrl() {
|
||||
return "";
|
||||
public List<Image> getParentChannelAvatars() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,9 +1,16 @@
|
||||
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
|
||||
|
||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
|
||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.getAllImagesFromArtworkOrAvatarUrl;
|
||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.getAvatarUrl;
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||
|
||||
import com.grack.nanojson.JsonArray;
|
||||
import com.grack.nanojson.JsonObject;
|
||||
import com.grack.nanojson.JsonParser;
|
||||
import com.grack.nanojson.JsonParserException;
|
||||
|
||||
import org.schabi.newpipe.extractor.Image;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.Page;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
@ -24,9 +31,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||
|
||||
public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
|
||||
private static final int STREAMS_PER_REQUESTED_PAGE = 15;
|
||||
|
||||
@ -68,30 +72,28 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getThumbnailUrl() {
|
||||
String artworkUrl = playlist.getString("artwork_url");
|
||||
public List<Image> getThumbnails() {
|
||||
final String artworkUrl = playlist.getString("artwork_url");
|
||||
|
||||
if (artworkUrl == null) {
|
||||
// If the thumbnail is null, traverse the items list and get a valid one,
|
||||
// if it also fails, return null
|
||||
try {
|
||||
final InfoItemsPage<StreamInfoItem> infoItems = getInitialPage();
|
||||
|
||||
for (final StreamInfoItem item : infoItems.getItems()) {
|
||||
artworkUrl = item.getThumbnailUrl();
|
||||
if (!isNullOrEmpty(artworkUrl)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
|
||||
if (artworkUrl == null) {
|
||||
return "";
|
||||
}
|
||||
if (!isNullOrEmpty(artworkUrl)) {
|
||||
return getAllImagesFromArtworkOrAvatarUrl(artworkUrl);
|
||||
}
|
||||
|
||||
return artworkUrl.replace("large.jpg", "crop.jpg");
|
||||
// If the thumbnail is null or empty, traverse the items list and get a valid one
|
||||
// If it also fails, return an empty list
|
||||
try {
|
||||
final InfoItemsPage<StreamInfoItem> infoItems = getInitialPage();
|
||||
|
||||
for (final StreamInfoItem item : infoItems.getItems()) {
|
||||
final List<Image> thumbnails = item.getThumbnails();
|
||||
if (!isNullOrEmpty(thumbnails)) {
|
||||
return thumbnails;
|
||||
}
|
||||
}
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -104,9 +106,10 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
|
||||
return SoundcloudParsingHelper.getUploaderName(playlist);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getUploaderAvatarUrl() {
|
||||
return SoundcloudParsingHelper.getAvatarUrl(playlist);
|
||||
public List<Image> getUploaderAvatars() {
|
||||
return getAllImagesFromArtworkOrAvatarUrl(getAvatarUrl(playlist));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,10 @@ package org.schabi.newpipe.extractor.services.soundcloud.extractors;
|
||||
|
||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
|
||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.clientId;
|
||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.getAllImagesFromArtworkOrAvatarUrl;
|
||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.getAllImagesFromTrackObject;
|
||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.getAvatarUrl;
|
||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.parseDateFrom;
|
||||
import static org.schabi.newpipe.extractor.stream.AudioStream.UNKNOWN_BITRATE;
|
||||
import static org.schabi.newpipe.extractor.stream.Stream.ID_UNKNOWN;
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||
@ -11,6 +15,7 @@ import com.grack.nanojson.JsonObject;
|
||||
import com.grack.nanojson.JsonParser;
|
||||
import com.grack.nanojson.JsonParserException;
|
||||
|
||||
import org.schabi.newpipe.extractor.Image;
|
||||
import org.schabi.newpipe.extractor.MediaFormat;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
@ -96,18 +101,13 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
|
||||
@Nonnull
|
||||
@Override
|
||||
public DateWrapper getUploadDate() throws ParsingException {
|
||||
return new DateWrapper(SoundcloudParsingHelper.parseDateFrom(track.getString(
|
||||
"created_at")));
|
||||
return new DateWrapper(parseDateFrom(track.getString("created_at")));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getThumbnailUrl() {
|
||||
String artworkUrl = track.getString("artwork_url", "");
|
||||
if (artworkUrl.isEmpty()) {
|
||||
artworkUrl = track.getObject("user").getString("avatar_url", "");
|
||||
}
|
||||
return artworkUrl.replace("large.jpg", "crop.jpg");
|
||||
public List<Image> getThumbnails() throws ParsingException {
|
||||
return getAllImagesFromTrackObject(track);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@ -155,8 +155,8 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getUploaderAvatarUrl() {
|
||||
return SoundcloudParsingHelper.getAvatarUrl(track);
|
||||
public List<Image> getUploaderAvatars() {
|
||||
return getAllImagesFromArtworkOrAvatarUrl(getAvatarUrl(track));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user