Triggered scripts

Is kJams missing a feature you need? Post it here! Note: if iTunes has it but kJams doesn't, it's a good bet kJams will have it, but that I just haven't gotten around to it yet. But go ahead and request it anyway!
Post Reply
DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Triggered scripts

Post by DeusExMachina »

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?

dave
Site Admin
Posts: 6684
Joined: Sun Sep 18, 2005 8:02 am
Location: Seattle
Contact:

Re: Triggered scripts

Post by dave »

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

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: Triggered scripts

Post by DeusExMachina »

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.

dave
Site Admin
Posts: 6684
Joined: Sun Sep 18, 2005 8:02 am
Location: Seattle
Contact:

Re: Triggered scripts

Post by dave »

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" ?

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: Triggered scripts

Post by DeusExMachina »

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.

dave
Site Admin
Posts: 6684
Joined: Sun Sep 18, 2005 8:02 am
Location: Seattle
Contact:

Re: Triggered scripts

Post by dave »

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

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: Triggered scripts

Post by DeusExMachina »

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.
Last edited by DeusExMachina on Thu Nov 01, 2018 6:45 pm, edited 2 times in total.

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: Triggered scripts

Post by DeusExMachina »

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.
Last edited by DeusExMachina on Sat Nov 10, 2018 3:19 pm, edited 1 time in total.

dave
Site Admin
Posts: 6684
Joined: Sun Sep 18, 2005 8:02 am
Location: Seattle
Contact:

Re: Triggered scripts

Post by dave »

for my testing, i use a tool called "Paw".
it's unit test looks like this:
paw_reg_notify.png
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'

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: Triggered scripts

Post by DeusExMachina »

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:
Window 2018-11-10 at 17.19.04.png
Last edited by DeusExMachina on Sun Nov 11, 2018 2:00 pm, edited 1 time in total.

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: Triggered scripts

Post by DeusExMachina »

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!

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: Triggered scripts

Post by DeusExMachina »

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:

Code: Select all

curl "http://localhost:12345/notify_register?url=http:%2F%2Flocalhost:12346" -H 'Cookie: sessionid=1'
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!
Last edited by DeusExMachina on Fri Nov 16, 2018 7:40 pm, edited 1 time in total.

dave
Site Admin
Posts: 6684
Joined: Sun Sep 18, 2005 8:02 am
Location: Seattle
Contact:

Re: Triggered scripts

Post by dave »

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

Post Reply