diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java index d308eb83..d6252279 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java @@ -1,13 +1,9 @@ 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.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.NewPipe; import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.StreamingService; @@ -20,11 +16,15 @@ import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; +import javax.annotation.Nonnull; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Objects; -import javax.annotation.Nonnull; +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; @@ -171,9 +171,25 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor { try { final JsonArray tracks = JsonParser.array().from(response); + // Response may not contain tracks in the same order as currentIds + final HashMap idToTrack = new HashMap<>(); for (final Object track : tracks) { if (track instanceof JsonObject) { - collector.commit(new SoundcloudStreamInfoItemExtractor((JsonObject) track)); + final JsonObject o = (JsonObject) track; + idToTrack.put(o.getInt("id"), o); + } + } + for (final String strId : currentIds) { + final int id = Integer.parseInt(strId); + try { + collector.commit(new SoundcloudStreamInfoItemExtractor( + Objects.requireNonNull( + idToTrack.get(id), + "no track with id " + id + " in response" + ) + )); + } catch (final NullPointerException e) { + throw new ParsingException("Could not parse json response", e); } } } catch (final JsonParserException e) {