Manual Library Update (Without XBMC running)
#1
I have a mixture of devices with a shared database on a (soon to be) headless mythtv and SMB linux server. I add new content to my server frequently by various methods, some are completely automated. For some of my less beefy client devices, (i.e. Raspberry Pi's) updating the shared database from the client side can degrade performance until the update is complete.


I found this page on the wiki for updating the library by remote. My plan was to use the command line option below to schedule a cron job to periodically update the database right there on the server, making it optional for the clients.
Code:
curl --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "mybash"}' -H 'content-type: application/json;' http://localhost:9191/jsonrpc


However, when I tested the command, I got the following:
Code:
curl: (7) couldn't connect to host
I got the same result when I changed localhost to the actual IP address for the server.


I also tried using the port number listed in my advancedsettings.xml file and got the following:
Code:
5.5.37-0ubuntu0.12.04.1b�01DB\+]s��NhBQNu$M;}'Emysql_native_password!��#08S01Got packets out of order


Based on the output above, I thought that I had managed to connect to the database by changing the port number. So, I looked at the man page for the curl command and added what I thought was a means of entering username and password credentials into the command (-u xbmc:xbmc) below:
Code:
curl --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "mybash"}' -H 'content-type: application/json;' -u xbmc:xbmc http://localhost:3306/jsonrpc


I got the following (equally cryptic, but slightly different) error:
Code:
5.5.37-0ubuntu0.12.04.1�Y8MZ^I4c��yW)a0h=7:\Bvmysql_native_password!��#08S01Got packets out of order


Any thoughts?

P.S. Keep in mind that this is also a MythTV backend whose database also uses MySQL. The two databases seem to get along just fine, but I don't want to break anything.
4 x OpenELEC 6.0.x (Kodi 15.2) on Rasberry Pi & Intel NUC

3 x Kodi 16.1 Jarvis on *buntu Xenial

6 x SPMC 16.4-2 on Android Mobile & TV Devices
Reply
#2
I might be being really stupid here, but how can you expect to connect to XBMC's json api, if XBMC isn't running ??

That said, your first line looks correct as long as the port number is the one you have set in XBMC and you have allowed control of XBMC via http. You might also need to 'allow programs on this PC to control XBMC' and 'programs on other systems' as well.

I know I have a very similar curl function in a script that gets the currently playing item from XBMC, and I have all those settings on.
Learning Linux the hard way !!
Reply
#3
(2014-07-01, 20:42)black_eagle Wrote: I might be being really stupid here, but how can you expect to connect to XBMC's json api, if XBMC isn't running ??

That said, your first line looks correct as long as the port number is the one you have set in XBMC and you have allowed control of XBMC via http. You might also need to 'allow programs on this PC to control XBMC' and 'programs on other systems' as well.

I know I have a very similar curl function in a script that gets the currently playing item from XBMC, and I have all those settings on.

Perhaps you're right. Not knowing much about MySQL, curl, or java, I assumed that the command somehow interfaced with MySQL without the need for XBMC. Guess I assumed wrong...
4 x OpenELEC 6.0.x (Kodi 15.2) on Rasberry Pi & Intel NUC

3 x Kodi 16.1 Jarvis on *buntu Xenial

6 x SPMC 16.4-2 on Android Mobile & TV Devices
Reply
#4
Yeah, you're not going to get this method to work without XBMC running. MySQL is the database, it is not XBMC specific. curl is translating a command line command into a url transaction. The scrapers are inside of XBMC, and called via commands in XBMC or through its external API. You could make a cron job that starts XBMC, waits for a bit for it to get up and running, then executes this curl command, then kills XBMC. Or you could just tell XBMC to rescan at startup which would eliminate the need for the curl command altogether.

Check over in the third party app forums and see if there is a media manager that interacts with the database directly. Its definitely possible to right a scraper that scans your videos and updates the database accordingly, it's just a question of whether or not someone's done that yet. Keep in mind such software would have to be updated alongside XBMC because if XBMC makes a change to the database structure the external program would need to be aware of it.
Reply
#5
(2014-07-01, 22:52)KeithLM Wrote: Yeah, you're not going to get this method to work without XBMC running. MySQL is the database, it is not XBMC specific. curl is translating a command line command into a url transaction. The scrapers are inside of XBMC, and called via commands in XBMC or through its external API. You could make a cron job that starts XBMC, waits for a bit for it to get up and running, then executes this curl command, then kills XBMC. Or you could just tell XBMC to rescan at startup which would eliminate the need for the curl command altogether.

Check over in the third party app forums and see if there is a media manager that interacts with the database directly. Its definitely possible to right a scraper that scans your videos and updates the database accordingly, it's just a question of whether or not someone's done that yet. Keep in mind such software would have to be updated alongside XBMC because if XBMC makes a change to the database structure the external program would need to be aware of it.

Thanks KeithLM. Most of my boxes do update at startup and that works fine. The ones I'm primarily concerned with are my Raspberry Pi's. From my original post, they take a pretty substanstial preformance hit while updating content on my SMB server, even when they're overclocked.

To get around this issue, using a remote app, I send a WOL packet to one of my faster machines, let it update the database, and shut it down after about 10 minutes. Kinda clumsy, but it works. Since my server is headless, I was hoping to find something that I could run as a daemon without the need to run the GUI.

I suppose I could set up a headless older machine to boot up something like OpenELEC every few hours or so with a 10 or 15 minute hibernation timer. That would do the trick, and make use of one of the old PCs I have lying around Blush.
4 x OpenELEC 6.0.x (Kodi 15.2) on Rasberry Pi & Intel NUC

3 x Kodi 16.1 Jarvis on *buntu Xenial

6 x SPMC 16.4-2 on Android Mobile & TV Devices
Reply
#6
Do any of your more powerful machines with XBMC run all the time? There is a plug-in that allows you to schedule regular updating of the database. I forgot the name, but it shouldn't be hard to find. I use it on mine and it checks for new content every four hours, with this all other machines don't ever need to check for updates.
Reply
#7
(2014-07-01, 23:26)KeithLM Wrote: Do any of your more powerful machines with XBMC run all the time? There is a plug-in that allows you to schedule regular updating of the database. I forgot the name, but it shouldn't be hard to find. I use it on mine and it checks for new content every four hours, with this all other machines don't ever need to check for updates.

No, I'm trying to keep all of this as green as possible. For the most part, using MythTV on the server, my client machines are substitutes for renting a bunch of boxes from my cable company. Don't want to offset my savings from that by hiking up my utility costs.
4 x OpenELEC 6.0.x (Kodi 15.2) on Rasberry Pi & Intel NUC

3 x Kodi 16.1 Jarvis on *buntu Xenial

6 x SPMC 16.4-2 on Android Mobile & TV Devices
Reply
#8
A bash script wouldn't be hard to write to do this, and then throw it into a cron job.

The beginning of one of mine looks like this
Code:
now=`date`

xbmcAddress=$1
xbmcCommand=$2  # Optional command statement
# Check if given address is online (9001 is xbmc HTTP control port)
# notify-send -t 1 "XBMC Checking script called on ${now}"
status=$(curl -s -m 1 --max-time 2 --head http://$xbmcAddress:9001/jsonrpc | head -n 1 | grep "HTTP/1.[01] [23]..")

if [ "$status" = "" ]
    then
    echo "Not running"
    exit 1
fi

if ! [ "$xbmcCommand" = "" ]
    then # we have a command so what is it ?
    if [ "$xbmcCommand" = "suspend" ] ### currently this is the only supported cmd
        then
        result=$(curl -s --data-binary '{"jsonrpc": "2.0", "method": "System.Suspend", "id":1}' -H 'content-type: application/json;' http://$xbmcAddress:9001/jsonrpc)
        exit 0
    fi
fi

Easy enough to change that to start XBMC if its not running,wait for it to start up (could just loop around the first curl command until if ! [ "$status" = "" ]), then send the library update command and then exit. If it is running, then its still updating, so just exit.
Change the idle settings in XBMC itself to exit if it is idle for, say 5 mins, so it will shut itself down and I reckon that will work.
Learning Linux the hard way !!
Reply
#9
The script in my sig implements many of the common JSON calls making remote library updates a trivial process, as well as waking clients with WOL packets and then suspending them again afterwards.

When using a shared database, the non-scraper clients just need to have their texture cache preloaded with any new artwork.
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
Reply
#10
You could get a spare RPI that runs 24/7 headless with XBMC running. It will cost very little and use almost no power. Use the JSON command to activate a scan from the RPI. It may take a little time, but it won't interfere with the watching on your other machines.

Or why not run XBMC headless on your server and do the same thing?

I have to say too, if the 'automated' systems are, eg, sickbeard and couchpotato, they have their own mechanisms to update xbmc, no need to write any scripts. It's just a matter of having a 'live' xbmc system to order to do the scrape.
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply

Logout Mark Read Team Forum Stats Members Help
Manual Library Update (Without XBMC running)0