Adding Tracks To 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(), the .AddTrack() method of the returned playlist object can be used.

.AddTrack() expects one parameter, TrackObject, which must be a track object. For adding a track to a playlist by ID, see the bottom example.

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 a track object with Spotify.Tracks.GetTrack() and the track's Spotify ID

C) Add a track to the new playlist with .AddTrack(), and the newly created track object

D) Will try to play the new playlist on the active device

NewPlaylist := Spotify.Playlists.CreatePlaylist("Test 123", false, "This is an example playlist made by Spotify.ahk")

TheTrack := Spotify.Tracks.GetTrack("5ogtb9bGQoH8CjZNxmbNHR")

NewPlaylist.AddTrack(TheTrack)
NewPlaylist.Play()

An alternative way to do this without getting a full track object is the Spotify.Playlists.PlaylistAddTrack() method, which takes a playlist ID and track ID, which would save us one web API call.

NewPlaylist := Spotify.Playlists.CreatePlaylist("Test 123", false, "This is an example playlist made by Spotify.ahk")

Spotify.Playlists.PlaylistAddTrack(NewPlaylist.ID, "5ogtb9bGQoH8CjZNxmbNHR")

NewPlaylist.Play()