Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions 27 Spotishell/Public/Playlists/Remove-PlaylistItems.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 the item 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.
Expand All @@ -28,8 +28,9 @@ function Remove-PlaylistItems {
$Id,

[Parameter(Mandatory, ValueFromPipeline)]
[Alias('Track')]
[array]
$Track,
$Item,

[string]
$SnapshotId,
Expand All @@ -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) {

$BodyHashtable = @{items = $Track[$i..($i + 99)] }
for ($i = 0; $i -lt $Item.Count; $i += 100) {
$end = [Math]::Min($i + 99, $Item.Count - 1)
$BodyHashtable = @{items = $Item[$i..$end] }
if ($SnapshotId) { $BodyHashtable.snapshot_id = $SnapshotId }
$Body = ConvertTo-Json $BodyHashtable -Compress

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.