Hey, I wanted a way to keep my XBMC library in sync with the downloads from rtorrent/rutorrent in an event based way. So I've come up with a simple script that notifies XBMC on any download completion and also scans in those downloads that go somewhere below the video source directories. Maybe someone finds it useful
in ~/.rtorrent.rc
the script, saved as ~/.xbmcnotify.sh
in ~/.rtorrent.rc
Code:
system.method.set_key = event.download.finished,update_xbmc,"execute=/home/xbmc/xbmcnotify.sh,\"Download finished\",\"$d.get_name=\",\"$d.get_base_path=\""
the script, saved as ~/.xbmcnotify.sh
Code:
#!/bin/bash
# Send a GUI notification to XBMC and optionally scan a directory to video library
# Checks that the directory begins with a path from XBMC video sources
user="xbmc"
pass="xbmc"
url="http://localhost:8080/jsonrpc"
sources="/home/xbmc/.xbmc/userdata/sources.xml"
if [ -z "$2" ]; then
echo "Usage: $0 title message [directory]" 1>&2
exit 1
fi
type curl >/dev/null 2>&1 || { echo >&2 "ERROR: Cannot find curl, aborting."; exit 1; }
curl -o /dev/null -s -X POST --fail -H "Content-type: application/json" -d "{\"jsonrpc\":\"2.0\",\"method\":\"GUI.ShowNotification\",\"params\":{\"title\":\"$1\",\"message\":\"$2\"}}" -u $user:$pass $url || { echo >&2 "ERROR: Check that the user/pass/url are correct and XBMC webserver is enabled and running."; exit 1; }
if [ -z "$3" ]; then
exit
else
if [ ! -f "$sources" ]; then
echo "ERROR: Cannot find XBMC sources file: "$sources". Check script configuration"
exit 1
fi
ourpath=($(sed -n "/<video>/,/<\/video>/p" $sources | grep "<path" | cut -d '>' -f 2 | cut -d '<' -f 1))
inarray() { local n=$1 h; shift; for h; do [[ $n = "$h"* ]] && return; done; return 1; }
if inarray $3 "${ourpath[@]}"; then
curl -o /dev/null -s -X POST -H "Content-type: application/json" -d "{\"jsonrpc\":\"2.0\",\"method\":\"VideoLibrary.Scan\",\"params\":{\"directory\":\"$3\"}}" -u $user:$pass $url
else
echo "NOTICE: Directory did not match any of the video sources, not scanning to library" 1>&2
exit 0
fi
fi