[SoundCloud] Apply changes in Extractors

This commit is contained in:
AudricV 2022-07-25 19:09:17 +02:00
parent a3a74cd566
commit 31da5beb51
No known key found for this signature in database
GPG Key ID: DA92EC7905614198
3 changed files with 54 additions and 43 deletions

View File

@ -1,11 +1,14 @@
package org.schabi.newpipe.extractor.services.soundcloud.extractors; 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.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.JsonObject;
import com.grack.nanojson.JsonParser; import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException; import com.grack.nanojson.JsonParserException;
import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs; import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs;
@ -59,15 +62,19 @@ public class SoundcloudChannelExtractor extends ChannelExtractor {
return user.getString("username"); return user.getString("username");
} }
@Nonnull
@Override @Override
public String getAvatarUrl() { public List<Image> getAvatars() {
return user.getString("avatar_url"); return getAllImagesFromArtworkOrAvatarUrl(user.getString("avatar_url"));
} }
@Nonnull
@Override @Override
public String getBannerUrl() { public List<Image> getBanners() {
return user.getObject("visuals").getArray("visuals").getObject(0) return getAllImagesFromVisualUrl(user.getObject("visuals")
.getString("visual_url"); .getArray("visuals")
.getObject(0)
.getString("visual_url"));
} }
@Override @Override
@ -95,9 +102,10 @@ public class SoundcloudChannelExtractor extends ChannelExtractor {
return ""; return "";
} }
@Nonnull
@Override @Override
public String getParentChannelAvatarUrl() { public List<Image> getParentChannelAvatars() {
return ""; return List.of();
} }
@Override @Override

View File

@ -1,9 +1,16 @@
package org.schabi.newpipe.extractor.services.soundcloud.extractors; 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.JsonArray;
import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser; import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException; import com.grack.nanojson.JsonParserException;
import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
@ -24,9 +31,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Objects; 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 { public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
private static final int STREAMS_PER_REQUESTED_PAGE = 15; private static final int STREAMS_PER_REQUESTED_PAGE = 15;
@ -68,30 +72,28 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
@Nonnull @Nonnull
@Override @Override
public String getThumbnailUrl() { public List<Image> getThumbnails() {
String artworkUrl = playlist.getString("artwork_url"); final String artworkUrl = playlist.getString("artwork_url");
if (artworkUrl == null) { if (!isNullOrEmpty(artworkUrl)) {
// If the thumbnail is null, traverse the items list and get a valid one, return getAllImagesFromArtworkOrAvatarUrl(artworkUrl);
// 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 "";
}
} }
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 @Override
@ -104,9 +106,10 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
return SoundcloudParsingHelper.getUploaderName(playlist); return SoundcloudParsingHelper.getUploaderName(playlist);
} }
@Nonnull
@Override @Override
public String getUploaderAvatarUrl() { public List<Image> getUploaderAvatars() {
return SoundcloudParsingHelper.getAvatarUrl(playlist); return getAllImagesFromArtworkOrAvatarUrl(getAvatarUrl(playlist));
} }
@Override @Override

View File

@ -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.SOUNDCLOUD_API_V2_URL;
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.clientId; 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.AudioStream.UNKNOWN_BITRATE;
import static org.schabi.newpipe.extractor.stream.Stream.ID_UNKNOWN; import static org.schabi.newpipe.extractor.stream.Stream.ID_UNKNOWN;
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; 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.JsonParser;
import com.grack.nanojson.JsonParserException; import com.grack.nanojson.JsonParserException;
import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
@ -96,18 +101,13 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
@Nonnull @Nonnull
@Override @Override
public DateWrapper getUploadDate() throws ParsingException { public DateWrapper getUploadDate() throws ParsingException {
return new DateWrapper(SoundcloudParsingHelper.parseDateFrom(track.getString( return new DateWrapper(parseDateFrom(track.getString("created_at")));
"created_at")));
} }
@Nonnull @Nonnull
@Override @Override
public String getThumbnailUrl() { public List<Image> getThumbnails() throws ParsingException {
String artworkUrl = track.getString("artwork_url", ""); return getAllImagesFromTrackObject(track);
if (artworkUrl.isEmpty()) {
artworkUrl = track.getObject("user").getString("avatar_url", "");
}
return artworkUrl.replace("large.jpg", "crop.jpg");
} }
@Nonnull @Nonnull
@ -155,8 +155,8 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
@Nonnull @Nonnull
@Override @Override
public String getUploaderAvatarUrl() { public List<Image> getUploaderAvatars() {
return SoundcloudParsingHelper.getAvatarUrl(track); return getAllImagesFromArtworkOrAvatarUrl(getAvatarUrl(track));
} }
@Override @Override