Fix SoundcloudPlaylistExtractor: tracks are in correct order
This commit is contained in:
parent
5c710da160
commit
bf70d32eb4
1 changed files with 22 additions and 6 deletions
|
@ -1,13 +1,9 @@
|
||||||
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.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.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;
|
||||||
|
@ -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.StreamInfoItem;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
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 {
|
public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
|
||||||
private static final int STREAMS_PER_REQUESTED_PAGE = 15;
|
private static final int STREAMS_PER_REQUESTED_PAGE = 15;
|
||||||
|
@ -171,9 +171,25 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final JsonArray tracks = JsonParser.array().from(response);
|
final JsonArray tracks = JsonParser.array().from(response);
|
||||||
|
// Response may not contain tracks in the same order as currentIds
|
||||||
|
final HashMap<Integer, JsonObject> idToTrack = new HashMap<>();
|
||||||
for (final Object track : tracks) {
|
for (final Object track : tracks) {
|
||||||
if (track instanceof JsonObject) {
|
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) {
|
} catch (final JsonParserException e) {
|
||||||
|
|
Loading…
Reference in a new issue