Hi all,
Newly registered (although I think I did register seveal years ago....) member here - long time user of Squeezebox Classic, for the past two years replaced by different other HW (thin clients running Daphile, Raspberry Pis running various incarnations of LMS....).
I also dabble in making stand-alone music players/servers, and have some (very basic) experience with messing with the internals of various Linux-based systems.
I've made a nice server using RasPi and Rune Audio (MPD-based audio server), putting it in a nice enclosure with built-in 16x2 character LCD, with the additon of a nice IR remote (for which I also did some work on the Python I2C driver) - see the attached photo...
Now I've decided to do the same, but using LMS (LMS server and squeezelite player in one compact standalone solution). I can reuse large part of the Python code responsible for communicating with LCD from my earlier work with Rune Audio - that's not the issue here.
However, since my Perl is quite rusty (and I never was any good at it, to be honest), even after several days of digging through the forum, and trying this and that, I still need some rather basic help.
Namely, I need to find (or insert into existing code) some kind of "trigger" which would "notify" my Python daemon that one of the events I'm interested in has happened - i.e. start/stop/pause/play, new track and volume change - in order to show those events immediately on the LCD.
I've checked the "subscribe" CLI command, using "telnet localhost 9090", and saw that I could e.g. use something like:
... and I *do* get notified of the events I'm interested in.
However, I'm at a loss of how to use this functionality as a kind of "service" that my Python daemon would subscribe to. I don't have a problem with parsing the received results, I can take care of that...
I've also managed to extract useful information from json/rpc, by using, e.g. this:
where "myhandler.py" parses the JSON result, and gives me something like this:
Artist: Bob Dylan
Title: Blowin' in the Wind
Album: The Freewheelin' Bob Dylan
Source: File
I can also see whether it's a file or e.g. radio playing, by seeing if the JSON result has 'remote' string in it, so that's also taken care of.... (I can see if the SOURCE is either e.g. "file" or "streaming").
I'd actually like more to use the JSON results than mess with telnet CLI (and the JSON result using curl also seems faster....), so if anyone has any suggestions/advise how to get the JSON result using the above mentioned "trigger event", I'm all ears.
In short, I need advice on either/or:
1) how to "subscribe" to CLI events as described above using Python
and/or
2) how to do detect a "trigger" for the events I'm interestd in, and get a full json response (like with 'curl' command above)?
The system I have worked on (Rune Audio) has a PHP worker script, and the developers have provided for such requirements - in their source code I can insert invocation of my bash script or a Python script, whatever.... I know exactly the place where the event has happened, and can insert my code there...
Rune Audio example (PHP script):
So, it would be nice if someone could direct me exactly how I could achieve something like this on LMS Linux (RasPi) installation...
Basically, I want to reflect changes in the Web UI (change of track, change of volume, stop/start/pause) on my LCD, showing artist and track (if the file or stream is playing) or "Stopped" or "Paused" if that is the status.
BTW, I've already solved the IR remote and remote comands, like this:
- this is a bash script command assigned to the "next" button on the remote....
So, most of the stuff is in place, but I just need to find the way to "glue" everything together - and for that, I need to find where and how to activate the proper "event trigger(s)"....
Sorry for the rather long-winded first post :(
Any help would be greatly appreciated!
TIA,
Denis
Newly registered (although I think I did register seveal years ago....) member here - long time user of Squeezebox Classic, for the past two years replaced by different other HW (thin clients running Daphile, Raspberry Pis running various incarnations of LMS....).
I also dabble in making stand-alone music players/servers, and have some (very basic) experience with messing with the internals of various Linux-based systems.
I've made a nice server using RasPi and Rune Audio (MPD-based audio server), putting it in a nice enclosure with built-in 16x2 character LCD, with the additon of a nice IR remote (for which I also did some work on the Python I2C driver) - see the attached photo...
Now I've decided to do the same, but using LMS (LMS server and squeezelite player in one compact standalone solution). I can reuse large part of the Python code responsible for communicating with LCD from my earlier work with Rune Audio - that's not the issue here.
However, since my Perl is quite rusty (and I never was any good at it, to be honest), even after several days of digging through the forum, and trying this and that, I still need some rather basic help.
Namely, I need to find (or insert into existing code) some kind of "trigger" which would "notify" my Python daemon that one of the events I'm interested in has happened - i.e. start/stop/pause/play, new track and volume change - in order to show those events immediately on the LCD.
I've checked the "subscribe" CLI command, using "telnet localhost 9090", and saw that I could e.g. use something like:
Code:
subscribe mixer,pause,stop,play,playlist newsong
However, I'm at a loss of how to use this functionality as a kind of "service" that my Python daemon would subscribe to. I don't have a problem with parsing the received results, I can take care of that...
I've also managed to extract useful information from json/rpc, by using, e.g. this:
Code:
curl -s -d '{"id":1,"method":"slim.request","params":["OPiSqueeze",["status","-",1,"tags:al"]]}' my-local-host:9000/jsonrpc.js | ./myhandler.py
Artist: Bob Dylan
Title: Blowin' in the Wind
Album: The Freewheelin' Bob Dylan
Source: File
I can also see whether it's a file or e.g. radio playing, by seeing if the JSON result has 'remote' string in it, so that's also taken care of.... (I can see if the SOURCE is either e.g. "file" or "streaming").
I'd actually like more to use the JSON results than mess with telnet CLI (and the JSON result using curl also seems faster....), so if anyone has any suggestions/advise how to get the JSON result using the above mentioned "trigger event", I'm all ears.
In short, I need advice on either/or:
1) how to "subscribe" to CLI events as described above using Python
and/or
2) how to do detect a "trigger" for the events I'm interestd in, and get a full json response (like with 'curl' command above)?
The system I have worked on (Rune Audio) has a PHP worker script, and the developers have provided for such requirements - in their source code I can insert invocation of my bash script or a Python script, whatever.... I know exactly the place where the event has happened, and can insert my code there...
Rune Audio example (PHP script):
Code:
//// ORIGINAL CODE
// save JSON response for extensions
$status['actPlayer'] = "MPD";
$redis->set('act_player_info', json_encode($status)); // this provides a JSON encoded status info (track, artist, volume, etc.) - similar to LMS status
////MY ADDITION BELOW
// here goes the call to my Python script with $status - for MPD
shell.exec('juggler.py ' . escapeshellarg(json_encode($status)) . '> /dev/null 2>&1 &'); // calls my Python script which parses the JSON data and sends info to LCD
// end of my addition
Basically, I want to reflect changes in the Web UI (change of track, change of volume, stop/start/pause) on my LCD, showing artist and track (if the file or stream is playing) or "Stopped" or "Paused" if that is the status.
BTW, I've already solved the IR remote and remote comands, like this:
Code:
#!/bin/bash
(echo "playlist index +1")|nc -w1 localhost 9090
So, most of the stuff is in place, but I just need to find the way to "glue" everything together - and for that, I need to find where and how to activate the proper "event trigger(s)"....
Sorry for the rather long-winded first post :(
Any help would be greatly appreciated!
TIA,
Denis