Triggered scripts
-
- Posts: 1292
- Joined: Sun Apr 20, 2008 9:57 am
- Location: Pittsburgh, PA
- Contact:
Triggered scripts
I know about per file launch scripts, and startup scripts, but any way to get scripts that trigger off transport controls or other UI interaction?
Specifically, for my current purpose, as I am sure you can guess, being able to trigger a script every time you play a new track would be perfect. (Trying to avoid an event loop!)
Also, is there a shutdown script to match the start up script?
Specifically, for my current purpose, as I am sure you can guess, being able to trigger a script every time you play a new track would be perfect. (Trying to avoid an event loop!)
Also, is there a shutdown script to match the start up script?
Re: Triggered scripts
another process can "subscribe" to push notifications (via HTTP), and you'll get notifications when a song starts, no matter how it starts.
see here:
https://karaoke.kjams.com/wiki/Server/Spec
specifically about "CWS_Path_NOTIFY_REGISTER"
other than that, no, there's not a way to trigger a script on these events
see here:
https://karaoke.kjams.com/wiki/Server/Spec
specifically about "CWS_Path_NOTIFY_REGISTER"
other than that, no, there's not a way to trigger a script on these events
-
- Posts: 1292
- Joined: Sun Apr 20, 2008 9:57 am
- Location: Pittsburgh, PA
- Contact:
Re: Triggered scripts
Does registering your own server preclude kJams from continuing to post communications to the standard server (i.e. can it handle more than one server at at time)?
Can you provide a few lines of example Python code that would register a server and make a query? The Server/Spec page is a bit unclear as to implementation.
Can you provide a few lines of example Python code that would register a server and make a query? The Server/Spec page is a bit unclear as to implementation.
Re: Triggered scripts
any number of subscribers is supported, they all get notifies.
oh, for python, i have no idea how you'd do that. this is really for a C++ app? google for "python web client" or "python curl" ?
oh, for python, i have no idea how you'd do that. this is really for a C++ app? google for "python web client" or "python curl" ?
-
- Posts: 1292
- Joined: Sun Apr 20, 2008 9:57 am
- Location: Pittsburgh, PA
- Contact:
Re: Triggered scripts
I was originally thinking something like this pseudo code:
import socket
# Set up a TCP/IP socket
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# Connect as client to server
# on specified port
s.connect(("localhost",12345))
while True:
response = s.recv(2)
if resp == "": break
if resp == kPushNotifyEvent_SONG_STARTED (or whatever the heck kJams returns to signify a new track just started)
do the shell script to run VLC,
# Close the connection when completed
s.close()
Gonna have to delve more deeply. Ugh. I was happy with AppleScript.
import socket
# Set up a TCP/IP socket
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# Connect as client to server
# on specified port
s.connect(("localhost",12345))
while True:
response = s.recv(2)
if resp == "": break
if resp == kPushNotifyEvent_SONG_STARTED (or whatever the heck kJams returns to signify a new track just started)
do the shell script to run VLC,
# Close the connection when completed
s.close()
Gonna have to delve more deeply. Ugh. I was happy with AppleScript.
Re: Triggered scripts
okay sure. i've never written an event driven app in python, but maybe that'll work i guess? yeah AppleScript is going away, it's python forever now
-
- Posts: 1292
- Joined: Sun Apr 20, 2008 9:57 am
- Location: Pittsburgh, PA
- Contact:
Re: Triggered scripts
Most of the code as written is in the do shell script portion, so shouldn't matter too much what the rest is written in.
That said, I am not sure how many people are even using scripts, so it might just end up being a vanity project.
Got most of it working though, and it DOES give some great features, such as a third Video Window that does not show showScreens (so it acts as sort of a monitor for when to put the CDG/MP4 back up) as well as offering crash protection.
One major issue though, is that there is a years' long bug in VLC where is just totally ignores volumes set via the command line. You can push it -volume 0 all day, every day, and it will just happily play at whatever volume it last played at! So I might have to set that via the script part itself. Not sure yet if VLC listens to that, either, though.
That said, I am not sure how many people are even using scripts, so it might just end up being a vanity project.
Got most of it working though, and it DOES give some great features, such as a third Video Window that does not show showScreens (so it acts as sort of a monitor for when to put the CDG/MP4 back up) as well as offering crash protection.
One major issue though, is that there is a years' long bug in VLC where is just totally ignores volumes set via the command line. You can push it -volume 0 all day, every day, and it will just happily play at whatever volume it last played at! So I might have to set that via the script part itself. Not sure yet if VLC listens to that, either, though.
Last edited by DeusExMachina on Thu Nov 01, 2018 6:45 pm, edited 2 times in total.
-
- Posts: 1292
- Joined: Sun Apr 20, 2008 9:57 am
- Location: Pittsburgh, PA
- Contact:
Re: Triggered scripts
So the syntax for sending the request to server via curl is a bit unclear. With kJams running and listening on 12345, it seems to ignore the initial request to register a new server.
Also, not sure curl is the way to go, anymore, at least for listening for the notification. Maybe just for setting the initial setup request to kjams, but not for listening for the event notifications. Definitely leaning toward sockets
But again, could you give here an example curl call that would use notify_request to set up a server, say, sending notifications to port 12346 (12345+1) on a kjams instance set in prefs to listen to the old default, 12345?
So far, nothing I am trying gets the right response back.
Also, not sure curl is the way to go, anymore, at least for listening for the notification. Maybe just for setting the initial setup request to kjams, but not for listening for the event notifications. Definitely leaning toward sockets
But again, could you give here an example curl call that would use notify_request to set up a server, say, sending notifications to port 12346 (12345+1) on a kjams instance set in prefs to listen to the old default, 12345?
So far, nothing I am trying gets the right response back.
Last edited by DeusExMachina on Sat Nov 10, 2018 3:19 pm, edited 1 time in total.
Re: Triggered scripts
for my testing, i use a tool called "Paw".
it's unit test looks like this: when i ask it to output that as a cURL command, it shows this:
it's unit test looks like this: when i ask it to output that as a cURL command, it shows this:
Code: Select all
curl "http://localhost/notify_register?url=http:%2F%2Flocalhost:12345" -H 'Cookie: sessionid=1'
-
- Posts: 1292
- Joined: Sun Apr 20, 2008 9:57 am
- Location: Pittsburgh, PA
- Contact:
Re: Triggered scripts
Yeah, you and I have discussed Paw before (as well as POSTman).
I am not sure how you have kJams set up, but unless you have the server listening on the default loop back port, not sure how a call to just "localhost" gets through to kJams in the first place.
Certainly doesn't on my machine (since that is the first thing I tried, skeptical though I was).
I even tried explicitly specifying a GET (since cURL defaults to POST, I think) and it got me nowhere.
Even on Paw:
I am not sure how you have kJams set up, but unless you have the server listening on the default loop back port, not sure how a call to just "localhost" gets through to kJams in the first place.
Certainly doesn't on my machine (since that is the first thing I tried, skeptical though I was).
I even tried explicitly specifying a GET (since cURL defaults to POST, I think) and it got me nowhere.
Even on Paw:
Last edited by DeusExMachina on Sun Nov 11, 2018 2:00 pm, edited 1 time in total.
-
- Posts: 1292
- Joined: Sun Apr 20, 2008 9:57 am
- Location: Pittsburgh, PA
- Contact:
Re: Triggered scripts
So, I tired with Paw what I had thought would work with cURL, namely, http://localhost:12345/notify_register with parameters, url=http://localhost:12346 (note the change in last number from 12345 to 12346) on the understanding that since, in prefs, I still have kJams listening on 12345, that to send it a request to send notifications to an ADDITIONAL client, I have set a new port.
This seems to work on Paw, but fails with cURL via Terminal.
Thus my original question vís-a-vís what cURL statement you had been envisioning.
Also, the Paw session just crashed kJams, so there's that!
This seems to work on Paw, but fails with cURL via Terminal.
Thus my original question vís-a-vís what cURL statement you had been envisioning.
Also, the Paw session just crashed kJams, so there's that!
-
- Posts: 1292
- Joined: Sun Apr 20, 2008 9:57 am
- Location: Pittsburgh, PA
- Contact:
Re: Triggered scripts
Scratch all that, I read through that too fast (plus the window was too small) and I missed the --header switch. Adding the --header switch, and passing the 'Cookie: sessionid=1' header was the trick. At least so far using the command:
eliminate the error that cURL was throwing back in terminal (and thus in scripts).
So now onward to actually get it to work and listen on 12346 (which for me is probably going to be a far bigger feat!) and respect my authority when I tell it to do something!
Code: Select all
curl "http://localhost:12345/notify_register?url=http:%2F%2Flocalhost:12346" -H 'Cookie: sessionid=1'
So now onward to actually get it to work and listen on 12346 (which for me is probably going to be a far bigger feat!) and respect my authority when I tell it to do something!
Last edited by DeusExMachina on Fri Nov 16, 2018 7:40 pm, edited 1 time in total.
Re: Triggered scripts
yes, my server is running on Port 80, which is the default port, so you don't have to specify it, it is assumed if you don't specify any port