Categories
Tech

Set XBMC to Auto Update Library

After getting XBMC Live installed on my Revo and getting my library setup, I couldn’t find a simple option to have XBMC watch my video folder and automatically update my library. In place of this missing functionality, I figured I would setup a simple timed job to automatically update my library for me every hour.

Before I get started, I should note that there is an option to automatically update the library when the box is booted up which may work for some people. You can find this under System > Video > Update Library on Startup. This option wouldn’t work for me though as I leave my box on 24/7 or at most just put it in a standby state.

See below for the details on how to setup a timed job (cron) to update your video or music library. This consists of installing the xbmc-send application and setting up a cron job (and enabling the EventServer).

Access the shell of your XBMC installation (either via SSH/putty or directly from the keyboard/Ctrl+Alt+F2) then run the following commands:

Update the Aptitude local repository:

sudo apt-get update

Enter the password for the super user if prompted (the default is ‘xbmc’).

Install the xbmc-send client:

sudo aptitude install xbmc-eventclients-xbmc-send

Enter the password for the super user if prompted (the default is ‘xbmc’).

Press Y to continue when prompted.

(Optional) Test out a command:

xbmc-send -a "Notification(Testing,XBMC Command Success.)"

You should see a quick notification box popup on your XBMC installation as soon as you press enter on the above command.

(Optional) Test if Cron is installed:

Oddly enough, cron was not installed by default on my XBMC-Live 9.11 (repack) installation so I had to manually install it first. To test if you have cron installed, try running the following command:

crontab -l

If you get an error that says something like “crontab: command not found” then you need to first install cron using the optional step below. If you get a listing of your cron entries or a message that says “no crontab for [username]” then you can skip the optional next step of installing cron.

(Optional) Install Cron:

sudo aptitude install cron

If prompted, enter the root user password and hit Y if prompted to continue.

Setup the Timed Job (Cron):

Edit the crontab entry for the root user, using the nano editor:

sudo env EDITOR=nano crontab -e

You should now see a blank, command prompt version of something similar to Wordpad. If your crontab was empty, all you will see is “# m h  dom mon dow   command”. Press down to start a new line and copy the following in:

0 * * * * /usr/bin/xbmc-send -a "UpdateLibrary(video)" >> /dev/null 2>&1

Press Ctrl+O to save. Press [enter] to confirm saving to the default filename. Press Ctrl+X to exit the nano editor. Congratulations, your cronjob should now be setup to run every hour!

Other Thoughts:

Here are some other ways to setup your cron job to run. Use these in place of the default line that you pasted into the editor in the last step above:

At midnight every day:

* 0 * * * /usr/bin/xbmc-send -a "UpdateLibrary(video)" >> /dev/null 2>&1

Every 3 hours:

* */3 * * * /usr/bin/xbmc-send -a "UpdateLibrary(video)" >> /dev/null 2>&1

At 4:30pm (16:30):

30 16 * * * /usr/bin/xbmc-send -a "UpdateLibrary(video)" >> /dev/null 2>&1

If the test command doesn’t work, you may need to enable the Event Server (XBMC Wiki Article). In 9.11 Camelot, this is under System > Network > Services > Allow programs on this system to control XBMC (and by default should be on).

You can also use the list of functions from the XBMC wiki to schedule other cronjobs or create your own shell scripts for more fun automation on the XBMC platform.

16 replies on “Set XBMC to Auto Update Library”

on my copy of 9.11 repack, i had to run “sudo apt-get update” first or else the cron install would fail to kick off

Thanks for this tip! I had to run that sudo apt-get update as well. Also I had to use “sudo env EDITOR=nano crontab -e” to edit the file through putty or I was in VI where the Down arrow and Ctrl-O don’t work the same way.

Hey – does XBMC need to be running for this to work?
I have it running as part of a script at 4am – however – XBMC is not running!
I tested it – and when I next ran XBMC (ubuntu) the video library was not updated?

I know the xbmc send command works (although it was while XBMC was running) – I tried the test output and the update video command, but do I need to force run xbmc before I run the update then kill xbmc – then shutdown?

Thanks for this script, works a treat!

My only issue is it wouldn’t update my music library. How can I tell xbmc to update my music library? secondarily, how can I tell xbmc to clean my music library (i.e., remove files from the library that no longer exist?). I tried settings the advanced setting, but all it did was delete my entire video library =(

Anyway, I was playing around with this – and came across the idea of using inotify to watch the library for content, rather than relying on timed jobs. This means you don’t have to wait for content to appear, it will add the content as soon as you add it to your media library

basically I installed inotify (on ubuntu):

sudo apt-get install inotify-tools

and then created a simple script that would run the correct command when there were any relevant changes made to the library directory:

#!/bin/bash
while inotifywait -r -e move -e modify -e create -e delete /home/media/Videos;
do
/usr/bin/xbmc-send -a “UpdateLibrary(video)” >> /dev/null 2>&1
sleep 2
/usr/bin/xbmc-send -a “UpdateLibrary(video)” >> /dev/null 2>&1
done

(the reason for the sleep was because the update didn’t seem to work if xbmc was running a screensaver at the time. if someone has a better way of doing this let me know)

then set the script to run on bootup and you’re laughing.

Enjoy!!

Thanks for the comments, Ramiro. The inotify method sounds pretty cool.

Per the List of Functions page ([url]http://wiki.xbmc.org/?title=List_of_Built_In_Functions[/url]) from the XBMC Wiki, you would just change ‘video’ to ‘music’ in the UpdateLibrary() commands from my instructions above. eg: UpdateLibrary(music)

First of all thanks for these handy lines.

But with the edit of the cron file, my xbmc reset it self to its default skin and settings.
I had to change the line 0 * * * * /usr/bin/xbmc-send -a “UpdateLibrary(video)” >> /dev/null 2>&1

to

0 * * * * /usr/bin/xbmc-send -a “UpdateLibrary(video)” >> /dev/sda1 2>&1 in order to function like normal.

I have XBMC on a USB stick, so mby that has something to do with it.
Anyway it works now 🙂

This looks like something I will have to give a go. The only question I have is your video library organization. Do you have your Movies all in one folder or are they broken down where each movie has their own folder?

Mark-
It shouldn’t matter how the library is organized, as long as XBMC is currently recognizing your naming convention. The commands above simply tell XBMC to kick off it’s internal job that updates the video library… so as long as manual library updates on your system work, then this should work as well.

Thanks for this tip, was wondering if there is a way to auto export the library on a regular basis. My thought is to have XBMC auto export the library every night (like around 3am) and then copy that file out to a network drive. I’ve had to rebuild my XMBC box a couple times, just recently after a storm where it would not boot. If I had a recent copy of the database it would save time for the reload, right? Thoughts?

Thanks Again.

Yes, it can be automated. Per the XBMC Wiki ([url]http://wiki.xbmc.org/?title=List_of_Built_In_Functions[/url]) you can use the following function:

[code] exportlibrary(music|video,false,filepath)
—>The given library will be exported to a single file stored at filepath location. above with the function below.[/code]

[code] exportlibrary(music|video,true,thumbs,overwrite,actorthumbs)
—>The given library is exported to single files with the given options. Here thumbs,overwrite and actorthumbs are boolean values (true or false).[/code]

If that’s what you want to do, I would put together a simple shell script that runs the export, then copies the export from your HTPC to the network drive. Just replace the UpdateLibrary() part of the code from the article above. Then you can just add a cron entry to call the shell script.

Awesome, thanks for the direction!! I’m not exactly sure how it would be written but you given me enough to do so trial and error! Doesn’t look too difficult at all, once I figure out the syntax for doing my video library export (I don’t use XBMC right now for music).

Thanks for the quick reply and the help!

Help!

I’ve install XBMC on my jailbroken Apple TV2 device. All went well, but I’m not able to setup the scraper for IMDB to get video information for Icefilms and TV’s addons.

The problem is I don’t know the location on the Apple TV2 device where I need to setup the location of the video, TV files library in set content to use various scraper.

I could not find the files location using SSH or using the search in XBMC. I read some where online I needed to setup the file directory before installing any of the addons, but that solution is only if I was using a PC with XBMC.

I’ve swiped out the Apple TV 2 device by reinstalling Seas0npass again to start over. I’ve installed XBMC again by using the install software in NitoTV which I’ve installed again on the Apple TV2 device.

Can anyone help me setup the video directory correctly so the scrapers can find the video library to show in selecting movies in Icefilms?

Thank you.

@xbmc user – I’m not sure exactly what you are trying to do, but I’ll try to provide some feedback. The scraper feature is intended to be used with local or networked content – it goes out to the internet to grab metadata about your local content (fanart, actors, plot, directors, etc). Being that the Apple TV 2 has very limited internal storage and no USB ports, that would leave us with networked storage to be used with scrapers. If you are looking for more information on XBMC Scrapers, I would check out the scrapers wiki page ([url]http://wiki.xbmc.org/?title=Scrapers[/url]) on XBMC.org.

I don’t have personal experience with IceFilms, but I understand that it’s a video addon that enables you to stream video. I would recommend you visit the XBMC Forums for help with that. There is a thread related to IceFilms on the ATV2 ([url]http://forum.xbmc.org/showthread.php?t=113249[/url]) as well as a dedicated thread for the IceFilms addon ([url]http://forum.xbmc.org/showthread.php?t=87703[/url]).

Leave a Reply

Your email address will not be published. Required fields are marked *