Spotifydl-Core
A simple package to download music tracks from spotify 🎵
Installation
> npm i spotifydl-core
Intialization
You need to intialize the Spotify
Class before acessing the methods inside it.
const Spotify = require('spotifydl-core').default
const credentials = {
clientId: 'your-client-id',
clientSecret: 'your-client-secret'
}
const spotify = new Spotify(credentials)
Methods
NOTE: Only some methods are shown here. Checkout the docs for a more in-depth documentation
Get Track ⏭️
await spotify.getTrack(track_url)
Download Track/Song ⬇️
await spotify.downloadTrack(track_url, file_name)
Get Artist 👩🎤🧑🎤
await spotify.getArtist(artist_url)
Get Album 💽
await spotify.getAlbum(album_url)
Get Playlist 🎧
await spotify.getPlylist(playlist_url)
Download an Entire playlist
await spotify.downloadPlaylist(playlist_url)
Usage Example
const fs = require('fs-extra')
const Spotify = require('spotifydl-core').default
const spotify = new Spotify({
clientId: 'acc6302297e040aeb6e4ac1fbdfd62c3',
clientSecret: '0e8439a1280a43aba9a5bc0a16f3f009',
})
const links = {
artist: 'https://open.spotify.com/artist/7ky9g1jEjCsjNjZbYuflUJ?si=2To3fmc-T9KuyyrQ-Qp5KQ',
album: 'https://open.spotify.com/album/3u3WsbVPLT0fXiClx9GYD9?si=pfGAdL3VRiid0M3Ln_0DNg',
song: 'https://open.spotify.com/track/1Ub6VfiTXgyV8HnsfzrZzC?si=4412ef4ebd8141ab'
};
(async () => {
const data = await spotify.getTrack(links.song)
console.log('Downloading: ', data.name, 'by:', data.artists.join(' '))
const song = await spotify.downloadTrack(links.song)
fs.writeFileSync('song.mp3', song)
})()
🙇 Special Thanks