Help Sending a curl request (UPDATE KODI)

Im starting too think that this is beyond my skill and understanding at the moment i have just been running the commands and haven’t relay got a clue whats happening

Im going too push this too a back burner for now until my skill and understanding improve

So I thank you all for the help and patience on this post

Please comment still if i get new suggestion i will still try and get this running im just not seeing any progress apart from when cweitkamp posted

curl -su <USER>:<PASSWORD> -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"VideoLibrary.Scan","id":1}' http://<IP>:8080/jsonrpc

that is the only time i have seen my library actually update

@job

[22:04:08] openhabian@openHABianPi:~$ "/etc/openhab2/scripts/Kodi_rescan.sh"
-bash: /etc/openhab2/scripts/Kodi_rescan.sh: /bin/bash^M: bad interpreter: No such file or directory
[22:04:37] openhabian@openHABianPi:~$ /etc/openhab2/scripts/Kodi_rescan.sh
-bash: /etc/openhab2/scripts/Kodi_rescan.sh: /bin/bash^M: bad interpreter: No such file or directory

@Sharpy Try to add this to your exec.things:

Thing exec:command:kodidbupdate [command="/usr/bin/curl -XPOST --data-binary {\"jsonrpc\":\"2.0\",\"method\":\"VideoLibrary.Scan\",\"id\":\"mybash\"} -H content-type:application/json http://<YOUR_KODI_IP>:8080/jsonrpc > /dev/null 2>&1", interval=86400, timeout=5, autorun=false] 

This will update your library automatically every 24h - if you want to update it manualy, you could do it via an item like this:

Switch  Kodi_DBUpdate   "DB Update"   { channel="exec:command:kodidbupdate:run" }

Wish you luck, that this will work - and have faith, you´ll learn a lot in the next weeks/months/years. :slight_smile:

Hi Simon Thanks for the reply

I don’t have the exec binding installed
i was told not too use it for this task i asked if i should create a script or use exec and ppl said just do a script

@Sharpy Saw that post - but I think it´s mostly because the syntax is strange and it´s not the best way to learn how to handle stuff/scripts in OH.

I would not know a reason, why you shouldn´t use the exec binding for tasks like this. But maybe I´m wrong and there are some disadvantages regarding limited threads or something, that I don´t know?!

Ok before i try Quick question

can i stop it from updating automatic every 24 hours

i’m not relay after auto update as Kodi can update its library on startup

im after getting OH to update one machine so i can copy the principle for my other machines running kodi and update all at the same time after i have added/removed media

Thanks I appreciate that , I will try , my faith is still here like i say i love OH , i have already learned quite abit since starting in December i can only imagine after years hopefully scripts ,coding,building sensors :slight_smile:

Afaik it´s sufficent to remove the interval from the thing command, then it will wait for the manual trigger.

//edit: interval=0 is the right setting for this usecase.

1 Like

sounds good :wink:

At this point i just want it too work or give a sign of progress its like im still on the start square of this task and i have devoted quite alot of time already and so have the people helping me :slight_smile:

I will install the Binding add the thing cant hurt

This will be my first text thing file my other things are created by paper ui my items and rules are text

2018-08-02 23:19:06.090 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Test.things'

2018-08-02 23:19:06.516 [WARN ] [hab.binding.exec.handler.ExecHandler] - Couldn't transform response because transformationService of type 'REGEX' is unavailable

==> /var/log/openhab2/events.log <==

2018-08-02 23:19:06.224 [hingStatusInfoChangedEvent] - 'exec:command:kodidbupdate' changed from UNINITIALIZED to INITIALIZING

2018-08-02 23:19:06.240 [hingStatusInfoChangedEvent] - 'exec:command:kodidbupdate' changed from INITIALIZING to ONLINE

Should i install regex transform too ?

Yeah, try to install the regex transformation too. I think that the --data-binary part in the command is kind of , or at least handled as, a regular expression.

I have installed the Exec Binding and the Regexx Transform

Added the Thing Exactly
Test.things

Thing exec:command:kodidbupdate [command="/usr/bin/curl -XPOST --data-binary {\"jsonrpc\":\"2.0\",\"method\":\"VideoLibrary.Clean\",\"id\":\"mybash\"} -H content-type:application/json http://192.168.0.16:8080/jsonrpc > NUL 2>&1", interval=86400, timeout=5, autorun=false]

I noticed this does not contain user/password my kodi is protected

i added the item exactly

Switch  Kodi_DBUpdate   "DB Update"   { channel="exec:command:kodidbupdate:run" }

Flipped the switch kodi did not update

Sry, missed that, than this should work:

Thing exec:command:kodidbupdate [command="/usr/bin/curl -XPOST --data-binary {\"jsonrpc\":\"2.0\",\"method\":\"VideoLibrary.Scan\",\"id\":\"mybash\"} -H content-type:application/json http://user:pass@192.168.0.16:8080/jsonrpc > /dev/null 2>&1", interval=86400, timeout=5, autorun=false]

Info: Kodi will execute the command once, immediately after you saved the things file, so you should see if it works without the need to trigger the item.

I can confirm that this worked but you used the VideoLibrary.Clean this cleans the library changing too VideoLibrary.Scan updated the library perfectly

Kodi did run the update as soon as i saved the thing file it also ran it after i pressed the button

Just need too remove the auto part of that now so its only manual…

I removed interval part and re saved it scanned the libary again

I can sleep soundly tonight now :smiley:

Haha, f*ck, sry dude - you´re right. Used one of the sample codes on the kodi wiki and didn´t recognize it was the VideoLibrary.Clean - Hope I didn´t wiped you´re whole library…

Changed that in my previous posts!

not a problem my NAS is always online and the machine running kodi constantly backups i could restore it easy

although i did run it before i noticed

Thanks for your help on that

:sweat: Sry again - Glad to hear, it´s working for you now!

I have been watching for a while now it works perfectly but it seems to be running the update db every 3 mins or so i have removed the interval ?

2018-08-02 23:21:14.393 [.ItemChannelLinkAddedEvent] - Link 'Kodi_DBUpdate-exec:command:kodidbupdate:run' has been added.


2018-08-02 23:22:40.294 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from NULL to ON

2018-08-02 23:22:40.491 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:23:01.187 [ome.event.ItemCommandEvent] - Item 'Kodi_DBUpdate' received command OFF

2018-08-02 23:23:44.256 [ome.event.ItemCommandEvent] - Item 'Kodi_DBUpdate' received command ON

2018-08-02 23:23:44.270 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:23:44.500 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:24:09.720 [ome.event.ItemCommandEvent] - Item 'Kodi_DBUpdate' received command OFF

2018-08-02 23:24:10.821 [ome.event.ItemCommandEvent] - Item 'Kodi_DBUpdate' received command ON

2018-08-02 23:24:10.834 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:24:11.024 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:31:17.544 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:31:59.122 [ome.event.ItemCommandEvent] - Item 'Kodi_DBUpdate' received command OFF

2018-08-02 23:31:59.133 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:33:39.188 [ome.event.ItemCommandEvent] - Item 'Kodi_DBUpdate' received command ON

2018-08-02 23:33:39.199 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:34:02.370 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:34:15.441 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:34:15.618 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:34:18.100 [ome.event.ItemCommandEvent] - Item 'Kodi_DBUpdate' received command OFF

2018-08-02 23:34:20.783 [ome.event.ItemCommandEvent] - Item 'Kodi_DBUpdate' received command ON

2018-08-02 23:34:20.794 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:34:21.015 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:34:25.569 [ome.event.ItemCommandEvent] - Item 'Kodi_DBUpdate' received command OFF

2018-08-02 23:34:53.666 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:34:53.890 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:35:28.391 [ome.event.ItemCommandEvent] - Item 'Kodi_DBUpdate' received command ON

2018-08-02 23:35:28.414 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:35:28.626 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:38:30.672 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:38:30.861 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:39:30.863 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:39:31.066 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:40:31.072 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:40:31.281 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:41:31.290 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:41:31.504 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:42:31.515 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:42:31.753 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:43:31.768 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:43:32.005 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:44:32.015 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:44:32.301 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:45:32.274 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:45:32.525 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:46:32.546 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:46:32.753 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:47:32.774 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:47:47.193 [ome.event.ItemCommandEvent] - Item 'Kodi_DBUpdate' received command OFF

2018-08-02 23:47:47.201 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:48:53.525 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:48:53.720 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:49:53.742 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:49:53.984 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

2018-08-02 23:50:53.999 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from OFF to ON

2018-08-02 23:50:54.218 [vent.ItemStateChangedEvent] - Kodi_DBUpdate changed from ON to OFF

Try

interval=0

iv added it just waiting

how did you do that how did you know what data too put inside the exec command ?

Was most of it copied from the kodi site and the rest standard too every exec command ?

I dont like not knowing how too do something it seems like a waste of everyone’s time who has helped when i didnt learn how too do it myself

From Exec Binding Doc

Thing exec:command:uniquename [command="/command/to/execute here", interval=15, timeout=5, autorun=false]

My Understanding
anything that works in commad line works in repacement of “command/to/execute” here ?

In the link you posted https://kodi.wiki/view/HOW-TO:Remotely_update_library theres the base url for the above mentioned json rpc cmd as an exmaple for the windows command line:

"C:\Program Files (x86)\cURL\curl.exe" -i -X POST -d "{\"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.Scan\", \"id\": \"mybash\"}" -H "content-type:application/json" http://user:pass@localhost:port/jsonrpc > NUL 2>&1

took that as a base for the exec command and trying around a bit - and this is definitely one of the downsides using the exec binding: the syntax. But after a few minutes, there was success.

The will to digg into some stuff and understand what you´re doing, is the key to success.

I know i’m on the right road :slight_smile: travelling in the right direction

Changing to interval 0 seems to have solved that