A TypeScript Node project to enable exporting and importing Spotify playlists in various formats.
👋 Archival Note
Key takeaways from this project are: there are some really wild authentication methods out there, Terraform is great but infrastructure is still software development (a PITA sometimes), and Nx (and other monorepo solutions) still have not won me over and I'm convinced they never will.
Any requests that need non-public data from Spotify need to provide the bearer token in their request. It can be provided as a header or in the body (the header takes precedence over the body, but the body should be preferred).
Headers
const headers = {
'x-spotify-token': '<BEARER_TOKEN>',
// ...other headers
};
Body
const body = {
token: '<BEARER_TOKEN>',
// ...other body values
};
On the Playlists page, you can select one or more playlists and export them to a file.
The UI can display up to 50 playlists per page, which is the recommended maximum number of playlists to export at once.
Use the checkboxes to select playlists and click the "Export" button. Once the download is ready, a pop-up modal will provide a link to download the file.
The endpoint is POST /api/playlists/export
and accepts a JSON body.
The body should include an array of playlist IDs and their owners' IDs.
const body = {
playlists: [
{
id: '<PLAYLIST_ID>',
ownerId: '<PLAYLIST_OWNER_ID>',
},
// ...
],
};
It will return a UTF-8, DEFLATE
-compressed zip archive. The archive contains a single file named export.json, which stores an array of playlists. Each playlist has the format of the GET /playlist
response.
The only exception is:
- if the playlist is not owned by the requesting user, it will not have a
tracks
property with the track list enumerated - if the playlist is owned by the requesting user, all of its tracks will be hydrated into the `tracks property
On the Import page, you can upload a playlists export file (one generated by Playlist Export) and it will be imported into the currently logged-in account.
The UI allows uploading a single zip file to the server.
The endpoint is POST /api/import
and accepts a zip file via a multipart form upload.
Only 1 file can be processed at a time, and it may be 1 MB at largest.
Per playlist in the file, if the playlist has tracks
, then it will be recreated in the current user's account. If the playlist does not have tracks
and the owner is not the same as the current user, it will be followed (if the owner is the same, only an error is returned).
It will return a report of the import, including the number of playlists imported, the total number of tracks across all playlists imported, and any import errors that occurred.