How to let XBMC scan for new content on network connect

by elm

I have a Raspberry Pi with Raspbmc in my living room to watch tv shows and stuff. XBMC is really great software. I have the Pi hooked up to an Airport Express and there is a problem. The Airport Express takes some time to connect to my wifi network. This takes so long that the Pi is done booting and XBMC is running for some minutes by the time the network comes up. This disables one very useful feature of XBMC: the automatic library scan. When XBMC tries to scan all the sources for new content the network is not available and so it does nothing or at least does not find anything new.

The solution is to set the network manager to send a command to XBMC to scan the video sources when the network comes up.

You need to place the following script in /etc/network/if-up.d/. Each script in this folder is called on network up. This script sends a JSON request to XBMC to scan all video sources for new content. You may need to change the user, password or the port if you changed them in the XBMC settings. This are the default settings.


# Don't run if the loopback device comes up
[ "$IFACE" != "lo" ] || exit 0

# Send JSON command to XBMC to scan video sources
/usr/bin/wget --header='Content-Type: application/json' --post-data='{"jsonrpc": "2.0", "method": "VideoLibrary.Scan", "params": {"directory": "" }}' http://xbmc:xbmc@ --spider
To install this script you need to ssh into the Pi and place it in /etc/network/if-up.d/xbmcupdate. Now you can enjoy your latest downloads linux distributions without any hazzle.

EDIT: The parameter directory seems to be mandatory now.