Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Spotify Metadata
#1
Hi, I've been using moode for a couple of years now and absolutely love it. I also like seeing album art and other metadata when I am listening to music, so I got a screen for my Raspberry Pi and it now sits comfortably on my desk displaying just that. I use Spotify's immense library to discover new music and this is when I think cover art and metadata are most useful, but unfortunately moode only shows a gray overlay with 'Spotify Active' on it.

After doing some research I found out that a common approach to the problem by other open source projects is using Spotify's Web API. Unfortunately it is limited, a bit clunky, the configuration process is not very user friendly and the end user has to agree to additional Terms of Service to use this API. Nevertheless I've created a very rough proof of concept and published it on github (https://github.com/sm00th/moode/tree/spotify) and asked if this approach can be considered to be used in moode. Tim suggested that I bring this up on the forum to discuss this feature with the broader community, see how much interest for the feature there is and how hard is the setup process.

Below are the instruction on how to set this up, but I must warn you that this is a very rough early prototype not designed for normal use, all it can do is show you some metadata for the currently playing track for authenticated user. It does not update automatically on track change and there is a high possibility of bugs. It is also possible that something goes wrong and breaks your installation so you'll have to install a fresh image, so before doing this doing at least a settings backup is recommended (Settings->System->Backup/Restore).

Install
This only works on moode9 installs.
Find out and note down the version of moode-player you are using:
Code:
apt show moode-player | grep 'Version:'


Or, if you don't have apt installed:
Code:
dpkg -l moode-player


Download and install the package:
Code:
curl -O https://dump.trac3r.net/moode-player_9.1.3-1spotmeta1_all.deb
sudo apt-get install ./moode-player_9.1.3-1spotmeta1_all.deb


Insert new fields into cfg database.
Code:
sudo moodeutl -q "INSERT INTO cfg_system (id, param, value) VALUES (176, 'spotifyclientid', '');"
sudo moodeutl -q "INSERT INTO cfg_system (id, param, value) VALUES (177, 'spotifyclientsecret', '');"
sudo moodeutl -q "INSERT INTO cfg_system (id, param, value) VALUES (178, 'spotifyredirecturl', '');"
sudo moodeutl -q "INSERT INTO cfg_system (id, param, value) VALUES (179, 'spotifytoken', '');"

Reboot.

Configure
To use this feature you'll have to get access to Spotify API which comes with Terms of Service you'll personally have to agree to and comply with.

Go to the Spotify dashboard and click Create app. Fill in app name and description, under Redirect URIs add your moode's full address + 
/spotify, so if you normally access moode at moode.test that would be http://moode.test/spotify, if you use an ip address instead of hostname: http://192.168.1.15/spotify. Select Web API in the list of APIs you are using and click Save.


On the app's page click Settings where you can find you Client ID and Client Secret (after you click View client secret link).

In moode go to Configure -> Renderers -> Spotify and fill in Client ID, Client Secret and Redirect URL with data from previous step.

Now go back to the main moode screen and start spotify playback. You will be redirected to a Spotify page where you'll need to login (if not logged in yet), give the app permissions to read your playback state. After that you'll be redirected back to moode where metadata about currently playing spotify song should be available.

Uninstall
To go back, downgrade the package (change the version after = to the version you were using):

Code:
sudo apt-get install moode-player=9.1.0-1moode1


Clean up database and session vars:

Code:
sudo moodeutl -q "DELETE FROM cfg_system WHERE param='spotifyclientid'
sudo moodeutl -q "DELETE FROM cfg_system WHERE param='spotifyclientsecret'"
sudo moodeutl -q "DELETE FROM cfg_system WHERE param='spotifyredirecturl'"
sudo moodeutl -q "DELETE FROM cfg_system WHERE param='spotifytoken'"
sudo moodeutl -D spotifyclientid
sudo moodeutl -D spotifyclientsecret
sudo moodeutl -D spotifyredirecturl
sudo moodeutl -D spotifytoken

Reboot.
Reply
#2
IIRC to detect track change the event script /var/local/www/commandw/spotevent.sh has to be modified to act on the env vars OLD_TRACK_ID and TRACK_ID. https://github.com/librespot-org/librespot/wiki/Events

When they are different send a command to the front-end JS function engineCmd() via /var/www/util/send-fecmd.php <command> that runs some code to update the metadata and cover art. Something like that.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
I've been using HiFiBerry before switching to MoOde and that's one thing I'm kind of missing, nice you're working on integrating this Smile
Reply
#4
Great initiative. I will try out in the coming days. The lack of display information makes me switch to other players, but coming back to moode every time.
Reply
#5
The install instructions work like a charm. I will dive into the suggestions of Tim to refresh with new track.
Reply
#6
I'm almost there. There is a refresh-screen command that can be called in spotevent.sh on event track_changed. The only glitch is that you see for less than one second the Spotify screen disappearing and coming in again. With some css adjustments it looks like this.
   
Reply
#7
That's great progress!

Regards,
Kent
Reply
#8
I didn't think I was bothered about having spotify metadata, but now I see this suddenly it seems I really do.

Smile
----------------
Robert
Reply
#9
Hey I just wanted to +1 this idea. I love the implementation you made! I'm currently building a project where I want to have the song title at the very least from the Spotify Connect instance. I noticed in a GitHub issue a dev posted https://github.com/librespot-org/librespot/issues/592 as a reference point. I know the Spotify API is easier but I too am sort of on the boat of using a daemon to just expose the metadata and pulling from there. I'm fairly new to this sort of thing but I wonder how one might go about going around the API and without having to directly rely on an account, a key and all that.
Reply
#10
(10-23-2024, 05:06 PM)humboldtsquid Wrote: (...) I wonder how one might go about going around the API and without having to directly rely on an account, a key and all that.

You can "curl" or "wget" the html page of Spotify for the track you want; and parse it: there are IDs in metadata tags that can be used to collect artist, album and album-art with subsequent loads.
I had a POC few (many...?) months ago. It may be slow, of course, compared to the Spotify API.
Reply


Forum Jump: