moveAvis.sh updated

UPDATE: I made some improvements and will now catch both shows that start with letters or numbers.
ANOTHER UPDATE: Turns out i was truncating the show name, it is fixed and I have updated the script and link to pastie.org too.

I updated my script to be totally generic now. It does not depend on matching the names of any specific TV shows now, since I know the filename will always contain SxxExx to indicate Season and Episode, I filter that way. If the directory for that show already exists it will simply move the file there, if it doesn’t it will create a new one. Otherwise, if it isn’t a TV show, it goes to the Movie directory. Also, since I’m now using ushare to serve media to my xbox 360, I put a wget call in to the ushare web port to update the files so the xbox picks them up immediately over uPnP.

#!/bin/bash
#
#/usr/local/bin/moveAVIs.sh
#
# Jay Holler 09-10-2009
# Find *.avi files in the Downloads directory and move them to
# the appropriate folder on the NFS share

storageDir=/storage/TV

cd /home/jayholler/Downloads

for i in *.avi
do
myFile=”$i”

if [[ “$myFile” =~ ([A-Za-z0-9\.]*)\.(S..E..).avi ]] ; then
File=${BASH_REMATCH[2]}.avi
PreShowName=${BASH_REMATCH[1]}
ShowName=$(echo $PreShowName | sed ‘s/\./ /g’)
echo “[*] A new episode of $ShowName is ready for your enjoyment: $File” > /tmp/emailmessage.txt && sleep 2
[ -d “$storageDir/$ShowName” ] || mkdir -v “$storageDir/$ShowName”
mv -v $myFile “$storageDir/$ShowName/$File”
wget http://localhost:49153/web/ushare.cgi?action=refresh -o /dev/null -P /dev/null
/usr/local/bin/email.sh
else
echo “[+] $myFile does not match our TV shows, pushing it to /storage/Movies on lunchbox” > /tmp/emailmessage.txt
mv -v “$myFile” /storage/Movies/$myFile
/usr/local/bin/email.sh
fi
done
exit 0

Here’s the same thing in nicer formatting: http://www.pastie.org/612353

Advertisements

Author: jayholler

A technology lover living in California with my wife and two children.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s