A lightweight Spotify downloader package. Written in Typescript, designed for Node.js, with native Node components.
Note: For now, only Ogg Vorbis is supported. AAC (mp4) support will be added soon.
Unlike other similar package which rely on YouTube to extract tracks, spdl
fetches content directly from Spotify’s servers, ensuring high-quality and non modified streams.
spdl
also acts as a lightweight wrapper around some commonly used Spotify internal APIs.
- Download music tracks in multiple formats and bitrates.
- Supports tracks and podcast episodes.
- Node.js stream support for flexible usage.
- Have a valid Spotify account.
- Get a Spotify cookie from your browser. (or, you can use a non-anonymous Spotify access token and skip this requirement)
Non-anonymous token refers to an access token which is got from a Spotify Account (logged in browser). A cookie is always a better option due to the fact that the access token can automatically refresh after the token expiry time.
This section assumes you use a Chromium-based browser but you can use any browser you like.
Doesn't matter if you don't have a Spotify Premium subscription, log in with any account you prefer.
- Go to your browser and head to the Spotify Web Player.
- Open the Developer tools (with F12 or whatever).
- Go to the Application section, next head to Cookies and look for "https://open.spotify.com" inside.
- Select that and in the list, look for the sp_dc cookie.
- Copy the sp_dc cookie value and you're good!
If you can't find the sp_dc cookie, then make sure you're logged in.
You can install the package via npm:
npm install spdl
For yarn users:
yarn add spdl
The base function of this package, which most likely you're here for: downloading tracks!
You can directly import the package, which is hybrid, you can use it either in CJS or ES modules, and use it as a function. Also note that this package is properly typed, so you shouldn't have any issue when using Typescript.
First, we must authenticate with the Spotify API, which can be made by providing a cookie, a non-anonymous token or creating a session with your username and password (coming soon).
Here's a short ytdl-core-like example for downloading a song to a file:
import { createWriteStream } from "node:fs";
import { Spotify } from "spdl";
// A very basic example:
async function download() {
const client = await Spotify.create({
cookie: "sp_dc=your-cookie-here"
});
const url = "https://open.spotify.com/track/45AepEzwUs3GjhNxhh49ip";
const stream = client.download(url, {
quality: "OGG_VORBIS_160"
});
stream.pipe(createWriteStream("song.ogg"));
}
download();
Note
The ytdl-core-like syntax only works for the spdl
function and is limited to downloads.
To use other API features, you must initialize a Spotify
class instance.
Note
For high quality formats, you must have a Spotify Premium account.
Keyword | Bitrate | Codec | Premium |
---|---|---|---|
OGG_VORBIS_96 | 96kbps | Vorbis | |
OGG_VORBIS_160 | 160kbps | Vorbis | |
OGG_VORBIS_320 | 320kbps | Vorbis | ✅ |
MP4_128 | 128kbps | AAC | |
MP4_128_DUAL | 128kbps | AAC | |
MP4_256 | 256kbps | AAC | ✅ |
MP4_256_DUAL | 256kbps | AAC | ✅ |
MP3_96 | 96kbps | MP3 |
This package does not save any username or password provided and neither sends them to third party services. The credentials provided will only interact with the Spotify API.
With node-spdl you are authenticating with your own account, which essentially means you are accesing your own authorized content.
The user is responsible for further actions performed with it's decrypted content. If you'd like to support your favorite artists, you can always play their tracks via the Spotify App.
Anyways, I made this package just for fun and experimentation, please use this tool with caution.
We are not related in any way with Spotify AB.