From 705aaaf0256c75d7ab8b63967f49f9e67f8871a3 Mon Sep 17 00:00:00 2001 From: wardbox Date: Sat, 14 Mar 2026 14:33:49 -0700 Subject: [PATCH 1/2] Rename Remove-PlaylistItems $Track parameter to $Item Aligns parameter naming with the API's "items" terminology. Adds [Alias('Track')] for backward compatibility. Closes #72 Co-Authored-By: Claude Opus 4.6 (1M context) --- .../Public/Playlists/Remove-PlaylistItems.ps1 | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Spotishell/Public/Playlists/Remove-PlaylistItems.ps1 b/Spotishell/Public/Playlists/Remove-PlaylistItems.ps1 index 3337ef7..2789ce0 100644 --- a/Spotishell/Public/Playlists/Remove-PlaylistItems.ps1 +++ b/Spotishell/Public/Playlists/Remove-PlaylistItems.ps1 @@ -2,19 +2,19 @@ .SYNOPSIS Remove one or more items from a user's playlist. .EXAMPLE - PS C:\> Remove-PlaylistItems -Id 'myPlaylistId' -Track @(@{uri = 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh' }, @{uri = 'spotify:track:1301WleyT98MSxVHPZCA6M' }) - Removes all occurrences of both tracks by specifying only uris in playlist with Id 'myPlaylistId' + PS C:\> Remove-PlaylistItems -Id 'myPlaylistId' -Item @(@{uri = 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh' }, @{uri = 'spotify:track:1301WleyT98MSxVHPZCA6M' }) + Removes all occurrences of both items by specifying only uris in playlist with Id 'myPlaylistId' .EXAMPLE - PS C:\> Remove-PlaylistItems -Id 'myPlaylistId' -Track @(@{uri = 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh'; positions = @(0, 3) }, @{uri = 'spotify:track:1301WleyT98MSxVHPZCA6M' ; positions = @(7) }) - Removes specific occurrence of both tracks by specifying both the uris and items positions in the playlist with Id 'myPlaylistId' + PS C:\> Remove-PlaylistItems -Id 'myPlaylistId' -Item @(@{uri = 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh'; positions = @(0, 3) }, @{uri = 'spotify:track:1301WleyT98MSxVHPZCA6M' ; positions = @(7) }) + Removes specific occurrence of both items by specifying both the uris and item positions in the playlist with Id 'myPlaylistId' .EXAMPLE - PS C:\> Remove-PlaylistItems -Id 'myPlaylistId' -Track @(@{uri = 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh' }) -SnapshotId 'mySuperPlaylistSnapshot' - Removes all occurrences of both tracks in the specific snapshot with Id 'mySuperPlaylistSnapshot' of the playlist + PS C:\> Remove-PlaylistItems -Id 'myPlaylistId' -Item @(@{uri = 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh' }) -SnapshotId 'mySuperPlaylistSnapshot' + Removes all occurrences of both items in the specific snapshot with Id 'mySuperPlaylistSnapshot' of the playlist .PARAMETER Id Specifies the Spotify ID for the playlist. - .PARAMETER Track - An array of objects containing Spotify URIs of the tracks and episodes to remove - It may contains specific positions of each tracks/episodes to remove (zero-indexed) + .PARAMETER Item + An array of objects containing Spotify URIs of the tracks and episodes to remove. + It may contain specific positions of each item to remove (zero-indexed). .PARAMETER SnapshotId The playlist's snapshot ID against which you want to make the changes. The API will validate that the specified items exist and in the specified positions and make the changes, even if more recent changes have been made to the playlist. @@ -28,8 +28,9 @@ function Remove-PlaylistItems { $Id, [Parameter(Mandatory, ValueFromPipeline)] + [Alias('Track')] [array] - $Track, + $Item, [string] $SnapshotId, @@ -41,9 +42,9 @@ function Remove-PlaylistItems { $Method = 'Delete' $Uri = "https://api.spotify.com/v1/playlists/$Id/items" - for ($i = 0; $i -lt $Track.Count; $i += 100) { + for ($i = 0; $i -lt $Item.Count; $i += 100) { - $BodyHashtable = @{items = $Track[$i..($i + 99)] } + $BodyHashtable = @{items = $Item[$i..($i + 99)] } if ($SnapshotId) { $BodyHashtable.snapshot_id = $SnapshotId } $Body = ConvertTo-Json $BodyHashtable -Compress From 31c2a7b9e57d7a96b8e2d52e64387e2c4b202c34 Mon Sep 17 00:00:00 2001 From: wardbox Date: Sat, 14 Mar 2026 14:40:13 -0700 Subject: [PATCH 2/2] Fix help text cardinality and final-batch slicing in Remove-PlaylistItems - Fix example description saying "both items" when only one item is shown - Use [Math]::Min to clamp slice end index, preventing trailing $null values in the JSON payload on the final batch Co-Authored-By: Claude Opus 4.6 (1M context) --- Spotishell/Public/Playlists/Remove-PlaylistItems.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Spotishell/Public/Playlists/Remove-PlaylistItems.ps1 b/Spotishell/Public/Playlists/Remove-PlaylistItems.ps1 index 2789ce0..51b099b 100644 --- a/Spotishell/Public/Playlists/Remove-PlaylistItems.ps1 +++ b/Spotishell/Public/Playlists/Remove-PlaylistItems.ps1 @@ -9,7 +9,7 @@ Removes specific occurrence of both items by specifying both the uris and item positions in the playlist with Id 'myPlaylistId' .EXAMPLE PS C:\> Remove-PlaylistItems -Id 'myPlaylistId' -Item @(@{uri = 'spotify:track:4iV5W9uYEdYUVa79Axb7Rh' }) -SnapshotId 'mySuperPlaylistSnapshot' - Removes all occurrences of both items in the specific snapshot with Id 'mySuperPlaylistSnapshot' of the playlist + Removes all occurrences of the item in the specific snapshot with Id 'mySuperPlaylistSnapshot' of the playlist .PARAMETER Id Specifies the Spotify ID for the playlist. .PARAMETER Item @@ -43,8 +43,8 @@ function Remove-PlaylistItems { $Uri = "https://api.spotify.com/v1/playlists/$Id/items" for ($i = 0; $i -lt $Item.Count; $i += 100) { - - $BodyHashtable = @{items = $Item[$i..($i + 99)] } + $end = [Math]::Min($i + 99, $Item.Count - 1) + $BodyHashtable = @{items = $Item[$i..$end] } if ($SnapshotId) { $BodyHashtable.snapshot_id = $SnapshotId } $Body = ConvertTo-Json $BodyHashtable -Compress