![]() |
[PROBLEM] Newbie questions: web interface login, Spotify and radio stations - Printable Version +- Moode Forum (https://moodeaudio.org/forum) +-- Forum: moOde audio player (https://moodeaudio.org/forum/forumdisplay.php?fid=3) +--- Forum: Support (https://moodeaudio.org/forum/forumdisplay.php?fid=7) +--- Thread: [PROBLEM] Newbie questions: web interface login, Spotify and radio stations (/showthread.php?tid=6164) |
RE: Newbie questions: web interface login, Spotify and radio stations - cogitech - 01-24-2024 I should note that the above librespot log entry is from my Debian workstation, running librespot from the command line. For the life of me, I cannot find where the heck librespot is logging to on moOde. Update: I found this https://moodeaudio.org/forum/showthread.php?tid=765&pid=6234#pid6234 So it is possible to turn logging on. Going to play with that and see what I can come up with. I think verbose logging is too much, so I will not use "-v". Update #2: Nope. That link above is too old. "/var/www/inc/playerlib.php" doesn't exist. Could not find playerlib.php anywhere in my file system. RE: Newbie questions: web interface login, Spotify and radio stations - Nutul - 01-24-2024 (01-24-2024, 03:40 PM)cogitech Wrote: So, parse the librespot log file for the latest "<spotify:track:XXXXXXXXXXXXXXXXXX>" entry, grab the track ID, inject it into the spotify-url-info tool, grab metadata and cover art, display in overlay. So, I haven't a Spotify premium account, so cannot use librespot and therefore do not have many track-IDs; just tested with the above. You can grab the bash script and test it on the Pi command line. I can retrieve the following information (it takes a couple of seconds, but this depends on the connection and servers availability / speed): artist, album, cover art, track number, track title, track duration the script is just a POC see if it is "enough" ETA This is what I can get on my Pi4 (the output is html-encoded, hence the &... thing) Code: pi@moode-lounge:~ $ /home/pi/bin/getSpotifyNowPlayingInfo.sh 5nTtCOCds6I0PHMNtqelas RE: Newbie questions: web interface login, Spotify and radio stations - TheOldPresbyope - 01-24-2024 (01-24-2024, 05:16 PM)cogitech Wrote: I should note that the above librespot log entry is from my Debian workstation, running librespot from the command line. grep is as good as find in cases like this. A quick grep on librespot found your missing bit (it moved when Tim refactored his code). Have a look at /var/www/inc/renderer.php Regards, Kent RE: Newbie questions: web interface login, Spotify and radio stations - cogitech - 01-24-2024 Awesome, guys! I'll do some tinkering. ![]() RE: Newbie questions: web interface login, Spotify and radio stations - cogitech - 01-24-2024 Okay, so tweaking the renderer.php works as expected and the log file always shows track ID when a new track is loaded: Code: 2024-01-24 20:44:48.414941 INFO [src/bin.rs:420] Capture finished And Al's script works as expected: Code: moode@moode:~ $ ./metaspot.sh 5qhGBRamxnwW6peITFjCPo Theoretically, that's all the "data" that we need, just need to figure out how to tie it all together and display it in the overlay. There is the problem of the log file to deal with, of course. Even though verbose logging is not necessary, eventually the log file will become a problem. That's a lot of wasted cycles and space when all we need, literally, is the most recent occurence of "Spotify URI <spotify:track:xxxxxxxxxxxxxxxxxxx>" in the log. Maybe there is a way to "watch" the log file for "Spotify URI <spotify:track:", parse the track ID, dump it to a state file, and route the rest of the log file to /dev/null ?? Then, Al's script could be written to watch the state file and grab new metadata any time the trackID in the state file changes. I bet there is a way better approach to this. I have been looking at "spotifyd", which appears to be a daemonized branch of librespot written in rust, with more "extras". From discussion I read, metadata was on the radar (and playback controls). I haven't had time to install it and play with it yet. RE: Newbie questions: web interface login, Spotify and radio stations - Nutul - 01-24-2024 (01-24-2024, 09:02 PM)cogitech Wrote: [2024-01-24T20:44:48Z INFO librespot::player_event_handler] Running ["/var/local/www/commandw/spotevent.sh"] with environment variables {"TRACK_ID": "0RffFIV29Yb7vjGokb0e6q", "PLAYER_EVENT": "playing", "POSITION_MS": "0", "DURATION_MS": "256875"} These messages cought my attention... I have no knowledge about librespot, but I see that a script is being called when the track changes, so that in that script we could add my commands to retrieve the relevant information. Then what remains to do is find a way to pass the relevant metadata to moOde, IDK, by invoking some php... existing or to-be-created... maybe @Tim Curtis can share a word here. Happy to see it works... as far as Spotify does not change the header of the pages it will continue to work for centuries to come... Maybe there is a way to download only the html head with curl, and this will possibly speed up the thing a little bit. RE: Newbie questions: web interface login, Spotify and radio stations - cogitech - 01-24-2024 (01-24-2024, 09:33 PM)Nutul Wrote:(01-24-2024, 09:02 PM)cogitech Wrote: [2024-01-24T20:44:48Z INFO librespot::player_event_handler] Running ["/var/local/www/commandw/spotevent.sh"] with environment variables {"TRACK_ID": "0RffFIV29Yb7vjGokb0e6q", "PLAYER_EVENT": "playing", "POSITION_MS": "0", "DURATION_MS": "256875"} Nice catch! It is even passing the "TRACK_ID" variable to the script. Interestingly, spotevent.sh does not reference that variable at all. Perhaps Tim had some plans for this in the future? I agree, it really looks like your script code could be integrated into spotevent.sh. Something like: if [[ $PLAYER_EVENT == "playing" ]]; then run Al's code with "$TRACK_ID" and dump the metadata [/to/some/file] Then the overlay php can grab what it needs from [/to/some/file]. RE: Newbie questions: web interface login, Spotify and radio stations - Nutul - 01-24-2024 (01-24-2024, 10:09 PM)cogitech Wrote: Interestingly, spotevent.sh does not reference that variable at all. Perhaps Tim had some plans for this in the future?This script, for what I see, is used to a) stop mpd when Spotify takes over, and b) eventually resume mpd playback when Spotify ends, and the behavior is set so in the configuration. Good it is there, so we can use it. Quote:I agree, it really looks like your script code could be integrated into spotevent.sh. Something like: We need also to check if the track ID is different from the last one. It could either write a file and some service at intervals could check it; or it may invoke the php, a more reactive solution IMO, if it is viable, of course. My script also needs to be tested during playback, to see what is the impact against the caller - that is: librespot, aka the player... if the call is blocking and the operation takes long, it could affect playback... ETA There are variables being set, at least this is what the log has to say... there is PLAYER_EVENT, OLD_TRACK_ID and TRACK_ID... so a if [ PLAYER_EVENT == changed && OLD_TRACK_ID != TRACK_ID ] should keep us on the safe side... There is also the DURATION and POSITION_MS, both in ms I am a bit rusty about shell variables... and can't use librespot, but I may think of giving you a small change to the spotevent.sh script just to check if we can detect the correct moment to interrogate spotify... RE: Newbie questions: web interface login, Spotify and radio stations - Nutul - 01-25-2024 (01-24-2024, 09:02 PM)cogitech Wrote: Hi, can you modify the /var/local/www/commandw/spotevent.sh and add the following lines, always, that is, before the very first IF (then we need to change that script, because ATM for any event other than "started" or "stopped" it just exits... adding these lines before the test at least gets us how-and-when it gets called...) echo "`date +%Y-%m-%dT%T.%N` - PLAYER_EVENT = ${PLAYER_EVENT}" >> /var/log/moode_spotevent.log echo "`date +%Y-%m-%dT%T.%N` - OLD_TRACK_ID = ${OLD_TRACK_ID}" >> /var/log/moode_spotevent.log echo "`date +%Y-%m-%dT%T.%N` - TRACK_ID = ${TRACK_ID}" >> /var/log/moode_spotevent.log echo "`date +%Y-%m-%dT%T.%N` - DURATION_MS = ${DURATION_MS}" >> /var/log/moode_spotevent.log echo "`date +%Y-%m-%dT%T.%N` - POSITION_MS = ${POSITION_MS}" >> /var/log/moode_spotevent.log Then, cast some songs in Spotify, and also do the following: 1. play a song, wait for it to finish, and play the next song. After some time you can stop it. 2. play a song, halfway through select another one to play 3. play a playlist, at least two songs (or do as at point 1) This to see how many times the script gets called; hopefully only one time per event (STOP / PLAYING / CHANGED) RE: Newbie questions: web interface login, Spotify and radio stations - cogitech - 01-25-2024 Hi @Nutul Thanks for that, I will try it later today if I have time. I also noticed that the script is executing sql commands, such as: Code: if [[ $PLAYER_EVENT == "started" ]]; then It seems to me that it might make more sense to do the same with the metadata. The db would need to be modified accordingly. Then the php code could pull the metadata and image url from the db (as I am sure it does for other parameters/settings, etc.). The only issue I see with this idea is that it requires quite a lot of work and the result is "eye candy". This is fun to work through, for sure, but at some point you have to ask "is it worth the effort"? I don't know. Is it? (after all, if someone wants to know what song is playing, simply look at the Spotify app on your phone/tablet) |