Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
Exctracting payload
Exctracting payload
Hi,
It's not often that I post asking for help but after several days of reading and trying different things I really need it.
I'm able to run this script and it prints in the log (screenshot)
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1700">
<Action>
EventGhost.PythonScript(u'PlayerID = eg.plugins.XBMC2.JSONRPC(u\'Player.GetActivePlayers\', u\'\', False)[0][\'playerid\']\neg.result = eg.plugins.XBMC2.JSONRPC(u\'Player.GetItem\', u"["+str(PlayerID)+",[\'title\']]", False)\nprint eg.result\n\nb = str(eg.result)\nb = b.split(" ",6)\nplaying=b[6]\neg.globals.playing = playing\nprint eg.globals.playing\n\nc = str(eg.globals.playing)\nc = c.split("\'",10)\ntitle=c[3]\neg.globals.title = title\nprint eg.globals.title\n\nd = str(eg.globals.title)\nd = d.split(".")\nshow=d[0]\neg.globals.show = show\nprint eg.globals.show')
</Action>
</EventGhost>
Now I try to use the payload with this script...
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1700">
<Action>
EventGhost.PythonScript(u'if eg.event.string == "XBMC2.Player.OnPlay.channel" and eg.event.payload == "u\'channel\', u\'id\': 20, u\'label\': u\'FNCHD/820\'}}":\n eg.TriggerEvent("FNC")')
</Action>
</EventGhost>
The script runs w/o error but doesn't generate an event based on the payload. I want to trigger events for specific channels to change the back light color.
Now I have other variable scripts that work fine for time and if then etc. But I just can't figure out this payload stuff.
thx
It's not often that I post asking for help but after several days of reading and trying different things I really need it.
I'm able to run this script and it prints in the log (screenshot)
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1700">
<Action>
EventGhost.PythonScript(u'PlayerID = eg.plugins.XBMC2.JSONRPC(u\'Player.GetActivePlayers\', u\'\', False)[0][\'playerid\']\neg.result = eg.plugins.XBMC2.JSONRPC(u\'Player.GetItem\', u"["+str(PlayerID)+",[\'title\']]", False)\nprint eg.result\n\nb = str(eg.result)\nb = b.split(" ",6)\nplaying=b[6]\neg.globals.playing = playing\nprint eg.globals.playing\n\nc = str(eg.globals.playing)\nc = c.split("\'",10)\ntitle=c[3]\neg.globals.title = title\nprint eg.globals.title\n\nd = str(eg.globals.title)\nd = d.split(".")\nshow=d[0]\neg.globals.show = show\nprint eg.globals.show')
</Action>
</EventGhost>
Now I try to use the payload with this script...
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1700">
<Action>
EventGhost.PythonScript(u'if eg.event.string == "XBMC2.Player.OnPlay.channel" and eg.event.payload == "u\'channel\', u\'id\': 20, u\'label\': u\'FNCHD/820\'}}":\n eg.TriggerEvent("FNC")')
</Action>
</EventGhost>
The script runs w/o error but doesn't generate an event based on the payload. I want to trigger events for specific channels to change the back light color.
Now I have other variable scripts that work fine for time and if then etc. But I just can't figure out this payload stuff.
thx
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Exctracting payload
Would be better if you copied the items as python an used the [ code ] [ /code ] markers around the code when your post unfortunately I am not in front of my PC. But I will do my best to help you give me a little time to remove all the XML markers gonna take a bit on my phone
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Exctracting payload
OK one problem I noticed offhand is that you are trying to compare a dictionary payload as a str
Its hard to tell without an exact copy of the whole payload data from the triggering event
But it does look like a dictionary
You can find out by using this in a script attached to the same event
print type(eg.event.payload)
And it will print in the log what kind of object container it is
May as well toss in a print eg.event.payload to get a complete copy of it and paste the information into the forum will help out greatly
So you would want to get rid of the event string if statement and change it to this
I am doing this from my phone and this gives the idea and is pseudo code
Edit: looked at the attached image it is a dictionary I have to modify the code
Its hard to tell without an exact copy of the whole payload data from the triggering event
But it does look like a dictionary
You can find out by using this in a script attached to the same event
print type(eg.event.payload)
And it will print in the log what kind of object container it is
May as well toss in a print eg.event.payload to get a complete copy of it and paste the information into the forum will help out greatly
So you would want to get rid of the event string if statement and change it to this
Code: Select all
data = eg.event.payload
ID = data['id'] if 'id' in data else None
label = data['label'] if 'label' in data else None
if ID == 20 and label == 'FNCHD/820':
eg.TriggerEvent(prefix='FNC')
Edit: looked at the attached image it is a dictionary I have to modify the code
Code: Select all
data = eg.event.payload
try:
if data['item']['label'] == 'FNCHD/820':
eg.TriggerEvent(prefix='FNC')
except:
pass
Re: Exctracting payload
thanks for helping. I updated my email address and now completely locked out of EG no activation email showed, so had to re register.
heres a screen and it is a dict. Tried both scripts but no joy. It seems its not able to pick out the payload
heres a screen and it is a dict. Tried both scripts but no joy. It seems its not able to pick out the payload
Re: Exctracting payload
Having serious issues with the forum. Anyway Heres some shots of the errors
thanks for helping.
thanks for helping.
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Exctracting payload
Make sure I have the key names right
The data var in the if statement should read
data['item']['title']
Sorry told ya I was doing this from phone
The data var in the if statement should read
data['item']['title']
Sorry told ya I was doing this from phone
Re: Exctracting payload
script is running but not triggering the event. I have to be missing something I can print the payload but the script isn't picking up on the title or channel
Re: Exctracting payload
GOT IT!! works perfect!!
thank you!!!
thank you!!!
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Exctracting payload
sorry about that error, i missed that when i was cutting and pasting and that's not an easy task when using a phone, as well as all the special characters
i have to remember to carry my BT keyboard with me. would make life so much easier.
I am happy it's working for you tho. not every payload in eventghost is a str
easy way to tell and to be 100% sure is to do a
or same thing with eg.result
because if the plugin dev didn't evaluate the incoming data then it's probably a string.
if the data was coming from a public source like a website that i didn't make then i wouldn't evaluate it because eval can be used to run code from that is transmitted to you in the form of a str and that could be bad. but if it's from a device or something i knew someone would be sending to them selves they have copntrol of the information so using eval there is no problem. because i do not think someone would write code as a str that could do harm to a system and then send it to themselves
***SCRATCHES HEAD***
but ya never can tell with some people.. LOL
K
i have to remember to carry my BT keyboard with me. would make life so much easier.
I am happy it's working for you tho. not every payload in eventghost is a str
easy way to tell and to be 100% sure is to do a
Code: Select all
print type(eg.event.payload)
because if the plugin dev didn't evaluate the incoming data then it's probably a string.
if the data was coming from a public source like a website that i didn't make then i wouldn't evaluate it because eval can be used to run code from that is transmitted to you in the form of a str and that could be bad. but if it's from a device or something i knew someone would be sending to them selves they have copntrol of the information so using eval there is no problem. because i do not think someone would write code as a str that could do harm to a system and then send it to themselves
***SCRATCHES HEAD***
but ya never can tell with some people.. LOL
K
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Exctracting payload
I would rather see you using this just in case the event get posted and the payload doesn't contain the necessary keys.
so you don't get all the ugly red traceback errors. this will throw the error, but has a means to catch the error, and i am going to make it more portable for you so you will just have to copy and paste the macro. and change a command to whatever channel you are looking to run an action on. that way it will become a lot easier to for ya..
give me a little while and i will make it so that you can copy and paste the thing right into your tree so you will have all the items made. and it should be pretty self explanatory
so you don't get all the ugly red traceback errors. this will throw the error, but has a means to catch the error, and i am going to make it more portable for you so you will just have to copy and paste the macro. and change a command to whatever channel you are looking to run an action on. that way it will become a lot easier to for ya..
give me a little while and i will make it so that you can copy and paste the thing right into your tree so you will have all the items made. and it should be pretty self explanatory
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Exctracting payload
ok here is the low down.
this is a folder item for EG so just copy the code and then right click in the tree and just paste
it should create all the necessary pieces
what you need to do is edit the action marked "#add the channel names here"
and this is what is in there
to add a channel it would look like this when done
nice thing about this is it will Trigger an event for you based on the channel name as well as preserve the payload for ya just in case you want to possibly still use it for other data that is in it and creates no additional global variables and you can use the event in multiple locations to do different things
it also shows some kind of visual in the log if it doesn't match with the stopping of the event (not necessary but nice to have the visual)
and here is the xml for the channel changing
this is a folder item for EG so just copy the code and then right click in the tree and just paste
it should create all the necessary pieces
what you need to do is edit the action marked "#add the channel names here"
and this is what is in there
Code: Select all
eg.result = ['FNCHD/820']
Code: Select all
eg.result = ['FNCHD/820', 'ADDED-CHANNEL']
it also shows some kind of visual in the log if it doesn't match with the stopping of the event (not necessary but nice to have the visual)
and here is the xml for the channel changing
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1700">
<Folder Name="Channel Change" Expanded="True">
<Macro Name="Processing Channel Change" Expanded="True">
<Event Name="XBMC2.Player.OnPlay.channel" />
<Action>
EventGhost.PythonCommand(u"eg.result = ['FNCHD/820'] #add the channel names here")
</Action>
<Action Name="Reading Channel Names">
EventGhost.PythonScript(u"try: data = eg.event.payload['item']['title']\nexcept: eg.result = None\nelse: eg.result = dict(prefix='ChannelChange', suffix=data, payload=eg.event.payload) if data in eg.result else None\n \n")
</Action>
<Action>
EventGhost.JumpIfElse(XmlIdLink(35), 0, False, XmlIdLink(33), False)
</Action>
</Macro>
<Macro Name="Stop Processing" id="33" Expanded="True">
<Action Name="Stopping Event">
EventGhost.StopProcessing()
</Action>
</Macro>
<Macro Name="Continue Processing" id="35" Expanded="True">
<Action Name="Triggering Event">
EventGhost.PythonScript(u'eg.TriggerEvent(**eg.result)')
</Action>
</Macro>
</Folder>
</EventGhost>
Re: Exctracting payload
man that is fantastic! I can't thank you enough for the advice and help!
Re: Exctracting payload
Just tried this and it's triggered some questions, hope you don't mind...
In the python statement, I've added FBNHD/821 so it looks like this eg.result = ['FNCHD/820'], ['FBNHD/821'] #add the channel names here, Now it jumps to stop processing. With FBN added it doesn't generate an event for FNC like it did. What am I missing?
Next, would you have any idea how I could add show name? xbmc has a field for showtitle.
thx
In the python statement, I've added FBNHD/821 so it looks like this eg.result = ['FNCHD/820'], ['FBNHD/821'] #add the channel names here, Now it jumps to stop processing. With FBN added it doesn't generate an event for FNC like it did. What am I missing?
Next, would you have any idea how I could add show name? xbmc has a field for showtitle.
thx
Re: Exctracting payload
Your code creates a tuple with two lists containing a string each. not quite what you want.fuqit2 wrote:In the python statement, I've added FBNHD/821 so it looks like this eg.result = ['FNCHD/820'], ['FBNHD/821']
Try this:
Code: Select all
eg.result = ['FNCHD/820', 'FBNHD/821'] jonib

