[GH-ISSUE #135] Is it possible to reorder more than one track at a time? #83

Closed
opened 2026-02-27 19:25:57 +03:00 by kerem · 5 comments
Owner

Originally created by @ilitotor on GitHub (Jul 28, 2018).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/135

Can I reorder, for example, 10 tracks at a time?
Put the last 10 track in the first positions?

Or just one by one?

thanks.

Originally created by @ilitotor on GitHub (Jul 28, 2018). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/135 Can I reorder, for example, 10 tracks at a time? Put the last 10 track in the first positions? Or just one by one? thanks.
kerem 2026-02-27 19:25:57 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@jwilsson commented on GitHub (Jul 28, 2018):

Hi!
Yes, you can reorder any number of tracks. An example putting the last 10 tracks first:

$tracks = $api->getPlayListTracks('PLAYLIST_ID');
$trackCount = count($tracks->items);

$api->reorderPlaylistTracks('PLAYLIST_ID', [
    'range_start' => $trackCount - 10,
    'range_length' => 10,
    'insert_before' => 0,
]);
<!-- gh-comment-id:408626608 --> @jwilsson commented on GitHub (Jul 28, 2018): Hi! Yes, you can reorder any number of tracks. An example putting the last 10 tracks first: ```php $tracks = $api->getPlayListTracks('PLAYLIST_ID'); $trackCount = count($tracks->items); $api->reorderPlaylistTracks('PLAYLIST_ID', [ 'range_start' => $trackCount - 10, 'range_length' => 10, 'insert_before' => 0, ]); ```
Author
Owner

@ilitotor commented on GitHub (Jul 30, 2018):

Hi, thanks for the quick response!

But, if I wanna put 10 tracks which are in non-sequential positions, in first?

For example: put track 4, 9, 13 in first. Or put in first 15, 9, 7, 11.

I tried to create a loop, but obviously, with each loop, the positions had already changed.

Is there a way to put an array first?

Thanks,

<!-- gh-comment-id:408868146 --> @ilitotor commented on GitHub (Jul 30, 2018): Hi, thanks for the quick response! But, if I wanna put 10 tracks which are in non-sequential positions, in first? For example: put track 4, 9, 13 in first. Or put in first 15, 9, 7, 11. I tried to create a loop, but obviously, with each loop, the positions had already changed. Is there a way to put an array first? Thanks,
Author
Owner

@jwilsson commented on GitHub (Jul 30, 2018):

Aha, I see. It doesn't look like it's possible to pass an array though.

But shouldn't you be able to solve it by using a loop? Something along the lines of updating range_start and/or insert_before on each iteration?

<!-- gh-comment-id:408945897 --> @jwilsson commented on GitHub (Jul 30, 2018): Aha, I see. It [doesn't look](https://developer.spotify.com/documentation/web-api/reference/playlists/reorder-playlists-tracks/) like it's possible to pass an array though. But shouldn't you be able to solve it by using a loop? Something along the lines of updating `range_start` and/or `insert_before` on each iteration?
Author
Owner

@jwilsson commented on GitHub (Jul 30, 2018):

Or on second thought, perhaps SpotifyWebAPI::replacePlaylistTracks() could be used together with SpotifyWebAPI::getPlayListTracks().

For example, getting all the tracks, reordering them, and then replacing the whole playlist.

$tracks = $api->getPlayListTracks('PLAYLIST_ID');

// Do some magic reordering...

$api->replacePlaylistTracks('PLAYLIST_ID', $reorderedTracks);
<!-- gh-comment-id:408947065 --> @jwilsson commented on GitHub (Jul 30, 2018): Or on second thought, perhaps `SpotifyWebAPI::replacePlaylistTracks()` could be used together with `SpotifyWebAPI::getPlayListTracks()`. For example, getting all the tracks, reordering them, and then replacing the whole playlist. ```php $tracks = $api->getPlayListTracks('PLAYLIST_ID'); // Do some magic reordering... $api->replacePlaylistTracks('PLAYLIST_ID', $reorderedTracks); ```
Author
Owner

@ilitotor commented on GitHub (Jul 30, 2018):

Amazing!

I will try this approach!

Thanks a lot

<!-- gh-comment-id:408960338 --> @ilitotor commented on GitHub (Jul 30, 2018): Amazing! I will try this approach! Thanks a lot
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-web-api-php#83
No description provided.