Removing Tracks From A Playlist
Wraps around this Spotify API endpoint
How to use
After getting a playlist through either Spotify.Playlists.GetPlaylist()
or creating a new playlist with Spotify.Playlists.CreatePlaylist()
(And adding tracks to the playlist), the .RemoveTrack()
method of the playlist object can be used.
.RemoveTrack()
expects one parameter, TrackID
which must be a track object and removes all instances of the track from the playlist. To remove a track from a playlist by track ID, see the example at the bottom of the page.
Example
This example will:
A) Create a new (empty and private) playlist named Test 123
with the description This is an example playlist made by Spotify.ahk
by calling Spotify.Playlists.CreatePlaylist()
B) Get 3 track objects with calls to Spotify.Tracks.GetTrack()
.
C) Add 5 tracks to the playlist, 3 copies of Ocean Man and the two other tracks, all using the .AddTrack()
method.
D) Wait for 10 seconds, then remove all copies of Ocean Man from the playlist
NewPlaylist := Spotify.Playlists.CreatePlaylist("Test 1234", false, "This is a Spotify.ahk test playlist")
FirstTrack := Spotify.Tracks.GetTrack("5ogtb9bGQoH8CjZNxmbNHR")
SecondTrack := Spotify.Tracks.GetTrack("2yYSMsrFJ6m7ePtLxQZZBF")
OceanMan := Spotify.Tracks.GetTrack("6M14BiCN00nOsba4JaYsHW")
NewPlaylist.AddTrack(FirstTrack)
NewPlaylist.AddTrack(SecondTrack)
loop, 3 {
NewPlaylist.AddTrack(OceanMan)
}
Sleep, 10000
NewPlaylist.RemoveTrack(OceanMan)
An alternative way to do this without getting full track objects is the Spotify.Playlists.PlaylistAddTrack()
method and the Spotify.Playlists.PlaylistRemoveTrack()
method, which both take a playlist ID and track ID, which would save us a few web API calls.
NewPlaylist := Spotify.Playlists.CreatePlaylist("Test 1234", false, "This is a Spotify.ahk test playlist")
Spotify.Playlists.PlaylistAddTrack(NewPlaylist.ID, "5ogtb9bGQoH8CjZNxmbNHR")
Spotify.Playlists.PlaylistAddTrack(NewPlaylist.ID, "2yYSMsrFJ6m7ePtLxQZZBF")
loop, 3 {
Spotify.Playlists.PlaylistAddTrack(NewPlaylist.ID, "6M14BiCN00nOsba4JaYsHW")
}
Sleep, 10000
Spotify.Playlists.PlaylistRemoveTrack(NewPlaylist.ID, "6M14BiCN00nOsba4JaYsHW")