I wasn't sure where the best place to post this was, so I put it here (since it relates to my unRAID SAB+XBMC installation).
I have often wanted a "Better" way for my SAB to update my video library when it finishes a download. I had a script where it would tell XBMC to scan, but it would scan the whole library. I noticed that Sickbeard tells XBMC to scan only the folder that was affected, so I went ahead and wrote my own script based on that. It's fairly simple (and I'm glad, since I'm new to Linux scripting) so I hope it helps someone!
Code: Select all
#!/bin/sh
echo ""
echo "Processing:"
echo " "$3
echo ""
echo "Original Download Location:"
echo " "$1
echo ""
echo "Checking directory..."
if [ -d "$1" ]
then
echo " Directory $1 exists!"
echo ""
echo "Converting directory to unRAID share..."
echo " Converted to: smb://angband/"${1:10}
wget -q "http://XBMCUSER:XBMCPASS@XBMCHOST:XBMCPORT/xbmcCmds/xbmcHttp?command=ExecBuiltIn¶meter=XBMC.updatelibrary(video,smb://angband/${1:10})"
echo ""
echo "Successfully Processed" $3
else
echo " Directory $1 is missing..."
echo ""
echo "Processing aborted for" $3
fi
It's important to use the share you have your movies under, and not just the raw path ($1). It would only work for me if I used my share.
Some presumptions about how things are setup.
unRAID: Hostname is "ANGBAND" for me, and the movie share is "movies". Remember to change this part in the script to match your needs!!
XBMC: This is running on a shared mySQL library (not important for the script, but important for the "sources" for XBMC's media files. Inside my XBMC, my library source is "smb://angband/movies". This way, no matter which machine I'm looking at my library on, it can access the files since they're on a network share and not machine specific.
XBMC must also be setup to allow other computers to send it commands (Settings -> Network). You'll need the XBMC machine's IP, port, user and password for later on.
For example:
RAW download path is: /mnt/user/movies/The Movie (2012)
Before I can process this download, I have to "fool" the script into thinking the file lives on my network share and not the actual path. So, I accomplish this by substring - that is I replace '/mtn/user/' with 'smb://angband' (the /movies part is common to both).
This is accomplished with the line:
wget -q "http://XBMCUSER:XBMCPASS@XBMCHOST:XBMCPORT/xbmcCmds/xbmcHttp?command=ExecBuiltIn¶meter=XBMC.updatelibrary(video,smb://angband/${1:10})"
XBMCUSER - this is your xbmc username
XBMCPASS - this is your xbmc password
XBMCHOST - this is the IP of the machine that's running xbmc and is responsible for library updates.
XBMCPORT - this is the port of that xbmc machine.
We're concerned with that bit at the end there, the ${1:10}. Essentially it says to take $1 or /mnt/user/movies/The Movie (2012), and remove the first 10 character, turning it into /movies/The Movie (2012). The part before that line prefixes my network share and tells XBMC to scan the video library, but only in that particular folder.
The other parts of the script are mostly "prettying" up the output and the bit about checking if the directory exists was just for my "knowledge" sake and could be taken out, but there's no harm in leaving it there.
Just save the code to a file (mine is UpdateLibrary.sh) and put it in the folder where SAB runs scripts from. Then assign it to the "movies" download category and let SAB update your movies for you! In my case, it went from a 5-10 minute process to less than 10 seconds to complete.