/send-spotify-love

Small script to send Spotify track links via SMS.

Primary LanguagePythonMIT LicenseMIT

Send Spotify Love 🎶 💚

Small amd simple python script to send spotify track links via SMS (yes, this still exists).

The script chooses a random track form a source playlist, sends the link via SMS and drops the track to a target playlist. The track will be removed from the source playlist. The script also sends warnings if the source playlist is (almost) emtpy or if tracks are already present in the source playlist.

Build with the spotipy and twilio client libraries.

Alternatively, you could write a telegram bot, or anything else that is more trendy then SMS, that does the job. Feel free to reach out if you want to contribute.

Getting Started

Prerequisite

Setup

Fill out all necessary configuration in the config.ini file. Phone numbers must be provided in E.164 format. Run python3 -u main.py and start sending great music.

The additional main(*args, **kwargs) function is used as an entry point for FAAS environments.

Note on the Spotify authentication

Short: set a random redirect URI (like https://localhost:8080) when setting up your Spotify App. When you run the script for the first time make sure to run it on a system that has a browser. Copy the link you are being redirected to to the console to create a cache file that holds your OAuth token. Future runs will work with that cache file.

Long: As the script is requesting user specific data, we need to go through a User Authorization flow (basically, we need to log into our Spotify account, get a token, store that somewhere. That token is then used to make the requests.). The basic principle behind this is OAuth. This process includes a callback URI that it can call and sent the token to once you have successfully logged into the service. For the purpose of this script, you can set the callback URI in your Spotify app to any URI (like https://localhost:8080). Make sure that the URI in config.ini matches your URI in the Spotify app settings.

Find out more on the Spotify authorization here.

When you run the script for the first time, the spotipy library will try to open a browser (make sure that you are running the script somewhere where there is a browser) and will walk you through the Spotify login process. Once done, don't get distracted by the error page, simply copy the link that your browser has tried to open to the python console and hit enter. The spotipy library will store the relevant tokens in the .sp_cache file. The script will automatically use the tokens from that cache file from now on (make sure to pass that cache file to your target environment).