Parsing info from Kodi

Hello everyone,

I am new on Node-red, and I have another problem. While music (i.e., from youtube) is playing on Kodi, I want to see the music title, artist, year, etc.

However, I see the information like this:

{"notification":"Player.OnAVStart","data":{"data":{"item":{"title":"World's Most Epic Music Ever: Pressed For Time (Amine Sebti)","type":"video","year":2016},"player":{"playerid":1,"speed":1}},"sender":"xbmc"}}

But they are not tidy. I would prefer to see the only title like "World's Most Epic Music Ever: Pressed For Time (Amine Sebti)"

I also use "node-red-contrib-kodi" and here is my flow:

[{"id":"3b137f22.17037","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"a91c535c.6f2df","type":"kodi-in","z":"3b137f22.17037","name":"kodi","controller":"d202ce84.24c45","x":263,"y":368,"wires":[["a8d5e129.5438b","95b72b4c.488658"]]},{"id":"95b72b4c.488658","type":"debug","z":"3b137f22.17037","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":622,"y":312,"wires":[]},{"id":"a8d5e129.5438b","type":"ui_text","z":"3b137f22.17037","group":"2f101410.857cfc","order":12,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":598.482666015625,"y":416.32275390625,"wires":[]},{"id":"d202ce84.24c45","type":"kodi-controller","z":"","name":"kodi","host":"localhost","port":"9090"},{"id":"2f101410.857cfc","type":"ui_group","z":"","name":"Kodi Kontrol","tab":"743f23a2.ece61c","order":5,"disp":true,"width":"6","collapse":true},{"id":"743f23a2.ece61c","type":"ui_tab","z":"","name":"R10 Dome","icon":"home","order":2,"disabled":false,"hidden":false}]

I have already checked "Node-Red Working with messages" and " Understanding and Using The Node-Red Message Object" but I still don't understand. Can anyone give me at least one working example?

I don't have the kodi node so i cannot import, but it is not really relevant.

Example flow:

[{"id":"6dba6cb0.40430c","type":"inject","z":"21514fd8.04e2a8","name":"","topic":"","payload":"{\"notification\":\"Player.OnAVStart\",\"data\":{\"data\":{\"item\":{\"title\":\"World's Most Epic Music Ever: Pressed For Time (Amine Sebti)\",\"type\":\"video\",\"year\":2016},\"player\":{\"playerid\":1,\"speed\":1}},\"sender\":\"xbmc\"}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":206,"y":216,"wires":[["ca1c0b9a.9ae0e8","6719054e.61334c"]]},{"id":"6719054e.61334c","type":"debug","z":"21514fd8.04e2a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":622,"y":216,"wires":[]},{"id":"ca1c0b9a.9ae0e8","type":"change","z":"21514fd8.04e2a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.data.data.item.title","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":392,"y":288,"wires":[["6719054e.61334c"]]}]

Check the change node to get a hint how to get the title.

1 Like

See also https://nodered.org/docs/user-guide/messages

Hello, thank you for your answers,

bakman2 I will check it; thank you, dceejay, I have already read that link, but I still can't handle; therefore, I have written here to ask any example. Thanks for your contribution.

For example, to pick up the title from your example configure a Change node to Move msg.payload.data.data.item.title To msg.payload.
At least I think that is the right path to move from, but as explained in the link you can get the debug window to copy that to the clipboard by clicking the little icon above it and then paste it into the Change node.

1 Like

Hello everyone,

First of all, I want to thank you for your interest. Now I understood the method so that I can try other attributes. Thank you very much!

Colin, I wasn't at home, so I will also try your advice, and I think the Change node will enable more than one attribute. (Edit: Sorry bakman2 also pointed for the change node. I need to add a node for each attribute I think)

Best regards!

Possibly, it depends on what you want to do with the data. Many nodes have the ability to extract a value from an attribute rather than requiring the value directly in the payload. For example if you wanted to display the title from your object in a text node on the dashboard you could feed the whole structure to the text node and configure it to show the value in msg.payload.data.data.item.title, so no Change node required.

1 Like

Hello Colin,

Great idea! I will try this. As I am a newbie in Node-Red, I have a long way to think from different angles. Thank you very much for your advice and ideas!

By the way, should I share my flow as an example? If you let me do this, I will also credit you, people. Maybe we can discuss this idea on another topic or here. You have a significant impact and effort on this work. Thank you again!

Hello again,

I am not sure if this message is appropriate to send after my last entry, but I wanted to add another issue.

The advice worked well, thank you, however, when I change the volume, the title becomes untidy and turn into a volume-related object. How can I keep the title even I change the volume? If I use to play/stop button, the volume related info disappears, and the title can be seen well. Nevertheless, this method, obviously, inconvenient.

I am open to hearing your advice and ideas again :slight_smile:

I suggest you start a new thread with this issue as it is not at all related to the thread title. You need to make the question clearer as personally I have no idea what you mean. Possibly a screenshot to show the issue.

1 Like

Hello Colin, I have started a new thread with this issue in this link

Click Here

Thank you for your interest!