Automatic library updater stopped working

The latest updates seem to have broken my Auto Library updater, this is a nice feature to have so does anyone know of a working addon which performs this function.

Shoog

I donā€™t know about the Auto Library Updater, but Iā€™m doing automatic updates with the below bash script on my dedicated server (executed as a cron job every hour).
This could also be implemented on a NAS or directly on the CE device itself (but the share needs to be mounted to CEā€™s filesystem).

#!/bin/bash

library_path="<your mounted share path>"
kodi_ip="<your CE device IP>"
remote_user="<username>"
remote_passwd="<password>"
remote_port="<port>"
tmp_file="/tmp/kodi_library_size"

ping -c 1 ${kodi_ip} > /dev/null
if [ $? == 0 ]; then
        if [ ! -f ${tmp_file} ]; then
                last_size=0
        else
                last_size=$(cat ${tmp_file})
        fi
        current_size=$(du -s ${library_path} | awk '{ print $1 }')

        if [[ ${last_size} -ne ${current_size} ]]; then
                curl -s --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "params": { "showdialogs": false }, "id": "scan"}' -H 'content-type: application/json;' http://${remote_user}:${remote_passwd}@${kodi_ip}:${remote_port}/jsonrpc > /dev/null
                echo ${current_size} > ${tmp_file}
        fi
fi

exit 0

You should adjust the variables to your environment, of course.
Itā€™s also necessary to activate http remote control in ā€œSettings > Services > Controlā€ and configure a username/password combination.
At first it checks, if the CE device is available on the network.
It reads a temporary file, which contains the last size of the share and compares it to the current share size. If it is the same, nothing is happening. If itā€™s different, a silent library scan is performed on the box using the jsonrpc API.
Due to the size check, you donā€™t perform unnecessary library scans, which decreases CPU and storage usage a lot.

You could also remove all these checks and just keep the jsonrpc call (the ā€œcurlā€ line).
Then you could execute it directly on the CE box without mounting the remote share.

All my Libraries are on USB HDDā€™s attached to the CE box so running such a script on the CE box would be fine.
Is there a fully functioning cron subsystem within CE, and if so where is the Crontab located ?

Seems to be a python problem breaking the addon.

Shoog

Iā€™ve never used cron jobs in CE, but normally it should be as easy as typing ā€œcrontab -eā€ into an SSH console to modify/create a crontab.

EDIT:
I just checked it, and there is a crond process running in the background.
Therefore the above command should be enough to add a crontab for the root user.

You should also adjust the $tmp_file variable to use anything within the /storage partition.

Yes invoking that command opens a crontab in nano.

So i just need to work out what needs doing to modify the script.

Shoog

Iā€™ve put everything, which is needed to configure the script, into variables at the beginning.
Should be easy to adjust it to your needs.
You could completely remove the IP check, because your box is obviously running, when executed on the CE device. :wink:

Will give it a go.

Shoog

This should be enough if executed locally:

#!/bin/bash

library_path="<your mounted share path>"
kodi_ip="127.0.0.1"
remote_user="<username>"
remote_passwd="<password>"
remote_port="<port>"
tmp_file="/storage/kodi_library_size"

if [ ! -f ${tmp_file} ]; then
        last_size=0
else
        last_size=$(cat ${tmp_file})
fi
current_size=$(du -s ${library_path} | awk '{ print $1 }')

if [[ ${last_size} -ne ${current_size} ]]; then
        curl -s --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "params": { "showdialogs": false }, "id": "scan"}' -H 'content-type: application/json;' http://${remote_user}:${remote_passwd}@${kodi_ip}:${remote_port}/jsonrpc > /dev/null
        echo ${current_size} > ${tmp_file}
fi

exit 0

Created that and did a test run, judging from the delays in executing it seems to be functional. Will see if it does the job when I add a few more items to the library tomorrow.

Cheers

Shoog

Iā€™ll keep my fingers crossed.
This script is doing its job for me since about two years without any problems.

Been trying to get this working for a bit now. Tried this code:

Seems to run, but no update is performed.
Should be simple right.

Shoog

Iā€™ve never tried it without a password set, and Iā€™m not sure, if the url is valid without one.
You could also change the $kodi_ip to ā€œ127.0.0.1ā€.

Try to just run the curl command without any checks (after setting a password):

curl -s --data-binary ā€˜{ ā€œjsonrpcā€: ā€œ2.0ā€, ā€œmethodā€: ā€œVideoLibrary.Scanā€, ā€œparamsā€: { ā€œshowdialogsā€: false }, ā€œidā€: ā€œscanā€}ā€™ -H ā€˜content-type: application/json;ā€™ http://kodi:password@127.0.0.1:8080/jsonrpc

If this works, there is something wrong with the size check.
Did you check the contents of /storage/kodi_library_size?
Does it contain your library size in 512 byte blocks?
Try to remove it to force a library re-scan the next time your cron job starts.

For debugging you can also change ā€œshowdialogsā€ within the curl command to ā€œtrueā€ and take a look at the Kodi GUI to see if it actually scans the library.

Ok that worked for me. it seems that my issue was with gnome terminal mangling the formating on a simple copy and past into nano. The curl line got choppped up and had CRā€™s added in. Corrected for this and did a test run of the script and it did a scan as instructed.

Great result and thanks for the perseverance.

Shoog

1 Like

Good to hear, it was a quiet easy solution.

I am still having issues getting the cronjob to run. The script runs as a simple command line call, but when I plug it into crontab -e it never seems to run. My crontab is

** 2/ *** /bin/bash /storage/scanlibrary

tried it with scanlibrary.sh, but that errored out.

Going to try the things mentioned in this thread:

Especially the line systemctl status cron -l. Cron is a simple system - but its debugging is not made easy. Hopefully that command will show how it is falling down.

OK with the aid of

I finally cracked what was going on, so this is the crontab line that finally got it working (pay attention to the spaces between the *'s):

* */2 * * * bash /storage/scanlibrary

Shoog