Improved SAB Movie script, maybe?
#1
Wink 
Hi all!
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:
#!/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&parameter=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

Ok, so some explanations. the $1 and $3 are parameters passed by SAB when it fires this script after downloading and unpacking. $1 represents the full path of the downloaded file, and $3 is the "name" of the file.

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&parameter=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.
Image
SpringsteenRadio.com: All Boss, All The Time
radioKAOS: killer internet radio
Reply
#2
Hi Tophicles,

Not to be disrespectul, and I am a fellow unRaid person, but isn't it much simpler to let Couchpotato handle all your movie searching, downloading and processing?

Even if I manually bookmark a movie I find on nzbMatrix, it is categorized via the RSS as a movie. After downloading, Sab moves it to the /downloads/complete/movies folder and Couchpotato finds it instantly, gets the metadata, thumbnail, etc, and moves it to the final folder for me, and invokes the "Update Videos" XBMC command.

Image
Reply
#3
(2012-07-27, 22:17)hernandito Wrote: Hi Tophicles,

Not to be disrespectul, and I am a fellow unRaid person, but isn't it much simpler to let Couchpotato handle all your movie searching, downloading and processing?

Even if I manually bookmark a movie I find on nzbMatrix, it is categorized via the RSS as a movie. After downloading, Sab moves it to the /downloads/complete/movies folder and Couchpotato finds it instantly, gets the metadata, thumbnail, etc, and movies it to the final folder for me, and invokes the "Update Videos" command.

No disrespect taken, I appreciate the comments!
I have to say that for the number of times I've used couch potato I find it to be REALLY kludgy and not work well at all. I wrote this mainly as a scripting tutorial for myself and to see if I could get it to work with my setup. Plus, I don't often browse IMDB to pick movies, or know what movies I want CP to look for. I usually just browse the indexing sites and grab stuff I think looks interesting Smile

So, for those of us who don't use CP, this might be a good solution.
Image
SpringsteenRadio.com: All Boss, All The Time
radioKAOS: killer internet radio
Reply
#4
I agree that, in the past, CP has been kludgy. I also think your script is great.

That said, you might like the new CP. V2 is pretty decent. You can even browse NZB sites, but add movies to a specific category that puts them through CP processing as if they were downloaded through CP initially.

None of this is to take away from what I'm sure is an excellent script, it's just another option for readers who find this thread looking for CP info.
Reply

Logout Mark Read Team Forum Stats Members Help
Improved SAB Movie script, maybe?0