Download 320kbps MP3s From Your Premium Spotify Account
Reading time: 4min
Recently I ran across a Node.js library called Spotijay which allowed you to download Spotify playlists to your hard-drive and keep them synced. While Spotify allows you to save tracks to your device for 'offline' listening, I've found that the app needs at least some small amount of data transfer just to start up. Which, in my eyes, kind of kills the primary benefit of having 'offline' tracks. This feature seems to be about saving bandwidth rather than listening to tracks with no cell service.
I ran into a few issues getting it set up, so I thought I would post the solutions in case it could help anyone else.
Prerequisites
- Homebrew: The Homebrew package manager should be installed.
- Spotify App Keys: Download your Spotify premium developer app key. Find your keys here.
Note: If you have not yet requested to be a Spotify developer, you will be asked to do so before your keys are made accessible.
Setting the groundwork
-
Update/upgrade Homebrew:
-
Install a few dependencies:
-
Clone the Spotijay repo to your desired location:
-
CD into the directory that you just cloned:
-
Grab the Spotify app key that you downloaded earlier and place it inside this directory.
-
Install NPM dependencies:
-
Install Forever. This is a tool that will keep the Spotijay script running continuously.
Note: If you see an error on this step, you may need to install libspotify from source. More info here.
Configuring Spotijay
Next we need to configure the app with Spotify authentication. For help, run:
This is where I ran into this error:
We can see from this error message that we seem to be missing a file here:
/usr/local/opt/libspotify/lib/libspotify
. Once we enter the lib
directory:
You should see these contents:
Note: This was not my first attempt at getting libspotify installed. So I may have more files listed here than you are seeing in your directory. The important one is
libspotify.dylib
.
Now, I'm not one to go changing file or directory names within library
directories all willy-nilly, but after reading this thread I
decided to give it a try. For safety's sake, I duplicated the
libspotify. dylib
file before changing the name. Then I simply removed the
.dylib
extension to match the file noted in the error message.
Just like that, node app.js help
worked beautifully.
Next up, we need to run the spotijay config script:
Nothing too magical here. We are simply calling config on the app.js server and passing in our a) user name, b) password and c) the destination folder (where the music will be saved).
At this point, you should be ready to begin downloading some music!
Running Spotijay
The Spotijay documentation references this command to begin:
But this did not work for me. I had to include my username in the call:
Note: A playlist URI will be a string of random characters like this:
5uSLUnV6U9easnPRO4rNu3
. The only way I know of to find the URI for a playlist is to open the Spotify web player and navigate to the desired playlist. In the browser address bar you should see a URL ending with the current playlist's URI such as:https://play.spotify.com/user/your_username/playlist/5uSLUnV6U9easnPRO4rNu3
While the Spotijay documentation doesn't mention it, by looking at the source code it seems that you can also download single tracks if you so desire.
Managing Forever
A few final notes
- If your Spotify account is used from anywhere else, Forever's connection with Spotify will be ended. Simply kill the Forever process and restart it.
- Spotijay will only download files that are not found in the directory. So no worries about duplicates when restarting process'.
- When waking your computer from sleep, Forever will pick right back up where it left off; no restart necessary.
The only other thing that I wish Spotijay did out of the box was support different directories per playlist call. I'm sure it would not be hard to extend the script (it's fairly small). Maybe I'll get around to that..someday.