Thank you for your donation!


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


Spotify / Librespot - metadata retrieval POC
#11
lol

IIRC from years past there was a project called "raspotify" that was getting metadata and covers. I'm not sure what approach was being used.

As a refresh, how are you currently getting metadata using the track id?
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#12
(01-31-2024, 08:47 PM)Tim Curtis Wrote: lol

IIRC from years past there was a project called "raspotify" that was getting metadata and covers.  I'm not sure what approach was being used.

As a refresh, how are you currently getting metadata using the track id?

I use curl to do exactly what a browser does: get the open-spotify page; then I filter the html through sed to get only some <meta> tags in the header with the information I need. I do 3 calls in cascade: one for the track, one for the album and the last one for the artist. I get text and IDs (that help for the subsequent "requests").
As I said, I can get everything moOde shows in the NowPlaying view.

Artist name
Album title + cover art URI + year
Track title + index + duration

(in the album there are also all the tracks, but since we have no automation there is no need in retrieving them... but they come in anyway, I just don't parse them)


I have made maybe 20 requests, and the average completion time on my Pi box is roughly between 2 and 3 seconds after the initial trackID submission.
All done through command piping, no tem files etc.

If you want I can give you the script to try it yourself; you'll have to take the track ID somehow... I opened spotify in my browser, and from a listed track click on the "three dots" => select "share" => select "Copy song link".
Then, from the song link just take the ID, which is the first parameter to the URI, and invoke my script with such ID as its parameter.

ETA
It's not the first parameter, but the LAST path in the URI: e.g.
https://open.spotify.com/track/4LytRM4HN7YQyEBbdRIlLE?si=e4d5a9621ef8485f

with the above I get

Artist: Snarky Puppy
Album : Live at the Royal Albert Hall
Track : 5 - Bad Kids To The Back - Live   (8:22)
Cover : https://i.scdn.co/image/ab67616d0000b273...80e1056a7d
Reply
#13
Seems like thats the only way to do it other than their WebAPI but thats not compatible with Open Source license.
It would prolly break if they change the DOM for that website.

In any case here's an overall approach

- Spotify event script writes trackID to /tmp file
- PHP daemon polls the file for change in trackID (or use inotify in a BASH daemon)
---- If changed, scrape the website and cache the data somewhere
---- Send a message + data to the front-end via sendEngCmd()
- Front end receives the message + data and updates the WebUI (only for chromium/local display) with new metadata from the cache
- If page is refreshed re-load metadata from cache into WebUI

Something like that.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#14
(01-31-2024, 11:15 PM)Tim Curtis Wrote: Seems like thats the only way to do it other than their WebAPI but thats not compatible with Open Source license.
It would prolly break if they change the DOM for that website.

In any case here's an overall approach

- Spotify event script writes trackID to /tmp file
- PHP daemon polls the file for change in trackID (or use inotify in a BASH daemon)
---- If changed, scrape the website and cache the data somewhere
---- Send a message + data to the front-end via sendEngCmd()
- Front end receives the message + data and updates the WebUI (only for chromium/local display) with new metadata from the cache
- If page is refreshed re-load metadata from cache into WebUI

Something like that.

Yes, that's the way I had in mind (without the details about sending the results to the UI).
A big difference, though:
There is no need to scrape the log, as librespot invokes the spotify script in non-blocking manner at every track change event, and passes over the track ID.
ATM such script exists straight away if the event is neither START nor STOP (used only to stop/start MPD).
We can add another one, or two events (need some investigation / testing to find out the most suitable) and then invoke (or inline the code, FWIW) the data retrieval and update the UI.

Thing is, I do not have a Spotify premium account that allows me to -connect to moOde and use librespot, IOW I cannot test its full functionality...
This is why I asked @cogitech to do some tests: playing tracks, skip tracks, select other tracks from a playlist and so on, with a modified script that added logs, in order to see what is getting called, how many times upon a (automatic vs manual) track change, etc. etc.

Ah, then also modify the script to prepare a json object, rather than just print its finds...
Reply
#15
Yes of course no need to scrape log files.

But you will prolly need to get a spot premium account if interested in making something happen. Its month to month so just cancel it after you're done testing. Thats what I do.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#16
(01-31-2024, 11:59 PM)Tim Curtis Wrote: Yes of course no need to scrape log files.

But you will prolly need to get a spot premium account if interested in making something happen. Its month to month so just cancel it after you're done testing. Thats what I do.

I was actually thinking about it... there's not much testing I can do without one.
Reply


Forum Jump: