Updating my scripts

I’m always looking for ways to improve my current media setup, I can never be satisfied. After speaking with a co-worker I discovered I could change the format of one of my scripts and I wound up cutting the number of lines from 533 to 234! Here is the new and improved script:

#!/bin/bash
#
#/usr/local/bin/moveAVIs.sh
#
# Jay Holler 10-29-2008
# A script to find *.AVI files in the Downloads directory and move them to
# the appropriate folder on the NFS share at lunchbox (192.168.1.128)

storageDir=/storage/TV

MOVE_FILE() {
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”
S=$(echo $File | sed -e ‘s/S0\(.\).*.AVI/\1/’)
E=$(echo $File | sed -e ‘s/S..E\(..\).*.AVI/\1/’)
if [ $E -lt 10 ]; then
episode=$(echo $E | sed -e ‘s/0\(.\)/\1/’)
/usr/local/bin/tvxml.sh “$ShowName” $S $episode TV $EpisodeID
else
/usr/local/bin/tvxml.sh “$ShowName” $S $E TV $EpisodeID
fi
wget http://localhost:49153/web/ushare.cgi?action=refresh -o /dev/null -P /dev/null
/usr/local/bin/email.sh
exit 0
}

## Look for AVI files and mv -v them over to the NFS Share on lunchbox
## Look for the shows we watch, and move files to the right place.
cd /home/jayholler/Downloads
for i in *.[A,a][V,v][I,i]
do
myFile=`echo $i | tr [:lower:] [:upper:]`
mv -v $i $myFile

case $myFile in

LOST*)
File=$(echo $myFile | sed ‘s/\(.*OST\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Lost’
MOVE_FILE
;;
ROBOT*)
File=$(echo $myFile | sed ‘s/\(.*KEN\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Robot Chicken’
MOVE_FILE
;;
BIG*)
File=$(echo $myFile | sed ‘s/\(.*OVE\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Big Love’
MOVE_FILE
;;
MAD*)
File=$(echo $myFile | sed ‘s/\(.*MEN\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Mad Men’
MOVE_FILE
;;
GLEE*)
GleeFile=$(echo $myFile | sed ‘s/\(.*LEE\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Glee’
MOVE_FILE
;;
REAL.HOUSEWIVES*)
File=$(echo $myFile | sed ‘s/\(.*SEY\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Real Housewives’
MOVE_FILE
;;
WIZARDS.OF.WAVERLY*)
File=$(echo $myFile | sed ‘s/\(.*ACE\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Wizards of Waverly Place’
MOVE_FILE
;;
ICARLY*)
File=$(echo $myFile | sed ‘s/\(.*RLY\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’iCarly’
MOVE_FILE
;;
DAISY.OF.LOVE*)
File=$(echo $myFile | sed ‘s/\(.*OVE\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Daisy of Love’
MOVE_FILE
;;
WEEDS*)
File=$(echo $myFile | sed ‘s/\(.*EEDS\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Weeds’
MOVE_FILE
;;
NURSE.JACKIE*)
File=$(echo $myFile | sed ‘s/\(.*KIE\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Nurse Jackie’
MOVE_FILE
;;
FAMILY.GUY*)
File=$(echo $myFile | sed ‘s/\(.*GUY\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Family Guy’
MOVE_FILE
;;
PUSHI*)
File=$(echo $myFile | sed ‘s/\(.*IES\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Pushing Daisies’
MOVE_FILE
;;
TRUE*)
File=$(echo $myFile | sed ‘s/\(.*LOOD\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’True Blood’
MOVE_FILE
;;
SUMMER*)
File=$(echo $myFile | sed ‘s/\(.*IGH\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Summer Heights High’
MOVE_FILE
;;
THE.TUDOR*)
File=$(echo $myFile | sed ‘s/\(.*ORS\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’The Tudors’
MOVE_FILE
;;
TIM.AND*)
File=$(echo $1 | sed ‘s/\(.*HOW\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Tim and Eric Awesome Show Good Job’
EpisodeID=’79905′
MOVE_FILE
;;
DOLLHOUSE*)
File=$(echo $myFile | sed ‘s/\(.*OUSE\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Dollhouse’
MOVE_FILE
;;
FLIGHT*)
File=$(echo $myFile | sed ‘s/\(.*ORDS\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Flight of the Conchords’
MOVE_FILE
;;
HEROES*)
File=$(echo $myFile | sed ‘s/\(.*EROES\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Heroes’
MOVE_FILE
;;
GOSSIP*)
File=$(echo $myFile | sed ‘s/\(.*IRL\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Gossip Girl’
MOVE_FILE
;;
THE.SECRET*)
File=$(echo $myFile | sed ‘s/\(.*AGER\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’The Secret Life of the American Teenager’
MOVE_FILE
;;
AMERICAN.IDOL)
File=$(echo $myFile | sed ‘s/\(.*DOL\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’American Idol’
MOVE_FILE
;;
AMERICAS.NEXT*)
File=$(echo $myFile | sed ‘s/\(.*ODEL\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Americas Next Top Model’
MOVE_FILE
;;
DEXTER*)
File=$(echo $myFile | sed ‘s/\(.*XTER\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Dexter’
MOVE_FILE
;;
90210*)
File=$(echo $myFile | sed ‘s/\(.*0210\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’90210′
MOVE_FILE
;;
THE.OFFICE*)
File=$(echo $myFile | sed ‘s/\(.*FFICE.US\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’The Office’
EpisodeID=’73244′
MOVE_FILE
;;
CALIFORNICATION*)
File=$(echo $myFile | sed ‘s/\(.*ION\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Californication’
MOVE_FILE
;;
ITS.ALWAYS*)
File=$(echo $myFile | sed ‘s/\(.*PHIA\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Its Always Sunny in Philadelphia’
MOVE_FILE
;;
DESPERATE*)
File=$(echo $myFile | sed ‘s/\(.*IVES\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Desperate Housewives’
MOVE_FILE
;;
PARIS*)
File=$(echo $myFile | sed ‘s/\(.*EVER\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Paris Hilton is my BFF’
MOVE_FILE
;;
THE.IT*)
File=$(echo $myFile | sed ‘s/\(.*ROWD\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’The IT Crowd’
MOVE_FILE
;;
HANNAH*)
File=$(echo $myFile | sed ‘s/\(.*TANA\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Hannah Montana’
MOVE_FILE
;;
ROCK*)
File=$(echo $myFile | sed ‘s/\(.*OVE\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’Rock of Love’
EpisodeID=’80610′
MOVE_FILE
;;
24.*)
File=$(echo $myFile | sed ‘s/\(.*4\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.AVI/’)
ShowName=’24’
MOVE_FILE
;;
*)
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
;;
esac
done
exit 0

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