A simple python script that grabs the most recent last.fm scrobbled Spotify song for the purpose of displaying the currently playing song in OBS.
To run this script, you will need to following:
- Python (or Python3) - Download
- Requests Python package. To install, run
py -m pip install requests
in your command line once Python is installed. - OBS (Preferred) - Download
- Spotify account - Link
- last.fm account - Link
Before running the scripts, you will need to enable last.fm scrobbling. This can be enabled by going to your Settings -> Applications, then connecting your spotify to last.fm.
You will also need a last.fm API Key to run the script. You can create an API account here. Once you have your key, add it to the API_KEY
variable in the python script. You will also need to specify your last.fm username in the USERNAME
field.
There are two scripts to choose from to run, currently_playing_html.py
will generate a song.html
file that looks like this:
This html document will self-refresh every 2 seconds to avoid OBS caching and not updating the preview. To add this preview in OBS, create a new Browser source, check the Local File
option and browse to the song.html
file. Change the width and height to 450 and 165 respectively. Your settings should look something like this:
The second script, currently_playing_txt.py
creates a text document. By default, the format of this text file is (song name) on (album name) by (artist)
. This can be customized in the first few lines of the script.
- Change
use_album_name
toFalse
if you do not want theon (album name)
to be added - Change
use_artist_name
toFalse
if you do not want theby (artist name)
to be added - Change
use_nowplaying_prefix
toTrue
if you wantNow playing
to be added to the beginning of the string.
To add the text file to OBS, create a new Text (GDI+) source, and click Read from file.
Browse to the song.txt
file and change the font to your preferences.