My Geeky TV setup

I have been working for a while at getting things just right with our TV setup, and I thought I would put it up so others could benefit from my work. Overall we are using 4 separate systems to run our entertainment center: A 32″ Westinghouse HDTV, an Apple TV, a Linux box which stores files on an NFS share, and another Linux box which does all the downloading, transcoding, and shifting around of files.

To start, I set up a giganews account, and an account at nzbsrus.com to download only the specific files which I desire. Then, I wrote a few scripts and got a few Linux utilities to handle everything for me, below is the process a file takes from start to end.

To start, I browse nzbsrus.com on my laptop for a certain show or movie, and have firefox configured to download the nzb file to my laptop. A cron job runs on my laptop that copies any nzb files over to LinuxBox1:

#!/bin/bash

for i in ~/Downloads/*.nzb; do scp ${i} jayholler@lunchbox:/home/jayholler/Downloads/; rm ${i}; done;
exit 0

LinuxBox1 is running a utility called fsniper, which hooks into filesystem events and executes actions you can configure manually. This is my fsniper config file:

watch {
~/Downloads {
*.avi {
handler = /usr/local/bin/moveAVIs.sh %%
}
*.nzb {
handler = mv %% /home/jayholler/.hellanzb/nzb/daemon.queue/
}
}

}

So when fsniper sees a new nzb file it drops it into a directory that another utility watches, called hellanzb. Hellanzb is a python program that automatically downloads, checks, and unrars files, and it can optionally be configured to run a script when it is done. So I have another little script which moves files back out from hellanzb’s directory to the directory fsniper is watching.

#!/bin/bash

for i in /home/jayholler/.hellanzb/done/*/*.avi; do mv “$i” /home/jayholler/Downloads/; done;
exit 0

Once fsniper sees the completed file, a final script is used to check which directory it should be moved to on the NFS share set up on LinuxBox2:

#!/bin/bash
#
#/usr/local/bin/moveAVIs.sh

AVI_DIR=/home/jayholler/Downloads

cd $AVI_DIR

function HEROES {

HeroesFile=`ls [Hh]er*.avi | sed ‘s/\(.*[s]\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.avi/’`
mv `ls [Hh]er*.avi` $HeroesFile
echo “[*] scp’ing $HeroesFile to basementbox” && sleep 2
scp $HeroesFile basementbox:/storage/TV/Heroes/
rm $HeroesFile
}

function FRINGE {

FringeFile=`ls [Ff]ri*.avi | sed ‘s/\(.*[e]\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.avi/’`
mv `ls [Ff]ri*.avi` $FringeFile
echo “[*] scp’ing $FringeFile to basementbox” && sleep 2
scp $FringeFile basementbox:/storage/TV/Fringe/
rm $FringeFile
}

function GOSSIP_GIRL {

GossipFile=`ls [Gg]os*.avi | sed ‘s/\(.*[l]\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.avi/’`
mv `ls [Gg]os*.avi` $GossipFile
echo “[*] scp’ing $GossipFile to basementbox” && sleep 2
scp $GossipFile ‘basementbox:/storage/TV/Gossip\ Girl/’
rm $GossipFile
}

function NEXT_TOP_MODEL {

ModelFile=`ls [Aa]me*.avi | sed ‘s/\(.*[l]\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.avi/’`
mv `ls [Aa]me*.avi` $ModelFile
echo “[*] scp’ing $ModelFile to basementbox” && sleep 2
scp $ModelFile ‘basementbox:/storage/TV/Americas\ Next\ Top\ Model/’
rm $ModelFile
}

function DEXTER {

DexterFile=`ls [Dd]ex*.avi | sed ‘s/\(.*[r]\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.avi/’`
mv `ls [Dd]ex*.avi` $DexterFile
echo “[*] scp’ing $DexterFile to basementbox” && sleep 2
scp $DexterFile basementbox:/storage/TV/Dexter/
rm $DexterFile
}

function Nine0210 {

mv `ls [9]02*.avi` $Nine0210File
echo “[*] scp’ing $Nine0210File to basementbox” && sleep 2
scp $Nine0210File basementbox:/storage/TV/90210/
rm $Nine0210File
}

function THE_OFFICE {

OfficeFile=`ls [Tt]he*[Oo]ffice*.avi | sed ‘s/\(.*[e]\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.avi/’`
mv `ls [Tt]he*[Oo]ffice*.avi` $OfficeFile
echo “[*] scp’ing $OfficeFile to basementbox” && sleep 2
scp $OfficeFile ‘basementbox:/storage/TV/The\ Office/’
rm $OfficeFile
}

function CALIFORNICATION {

CaliFile=`ls [Cc]ali*.avi | sed ‘s/\(.*[n]\).\([Ss][0-9]*[Ee][0-9]*\).*/\2.avi/’`
mv `ls [Cc]ali*.avi` $CaliFile
echo “[*] scp’ing $CaliFile to basementbox” && sleep 2
scp $CaliFile ‘basementbox:/storage/TV/Californication/’
rm $CaliFile
}

## Look for avi files and scp them over to the NFS Share on basementbox
## Call each function, look for the shows we watch, and move files to the right place.

if [[ “$1” =~ heroes* ]]; then
HEROES
exit 0
elif [[ “$1” =~ Heroes* ]]; then
HEROES
exit 0
elif [[ “$1” =~ fringe* ]]; then
FRINGE
exit 0
elif [[ “$1” =~ Fringe* ]]; then
FRINGE
exit 0
elif [[ “$1” =~ gossip* ]]; then
GOSSIP_GIRL
exit 0
elif [[ “$1” =~ Gossip* ]]; then
GOSSIP_GIRL
exit 0
elif [[ “$1” =~ america* ]]; then
NEXT_TOP_MODEL
exit 0
elif [[ “$1” =~ America* ]]; then
NEXT_TOP_MODEL
exit 0
elif [[ “$1” =~ dexter* ]]; then
DEXTER
exit 0
elif [[ “$1” =~ Dexter* ]]; then
DEXTER
exit 0
elif [[ “$1” =~ 90210* ]]; then
Nine0210
exit 0
elif [[ “$1” =~ office* ]]; then
THE_OFFICE
exit 0
elif [[ “$1” =~ Office* ]]; then
THE_OFFICE
exit 0
elif [[ “$1” =~ californication* ]]; then
CALIFORNICATION
exit 0
elif [[ “$1” =~ Californication* ]]; then
CALIFORNICATION
exit 0
elif [[ “$1” =~ *.mkv ]]; then
echo “Looks like we have an mkv file, sending this to appletv.sh…”
/usr/local/bin/appletv.sh “$1”
exit 0
else
echo “$1 does not match our TV shows, sending it to /storage/Movies/”
scp “$1” ‘basementbox:/storage/Movies/’
fi
exit 0

Finally, the Apple TV is hacked to mount the NFS share on LinuxBox2, expanding the amount of material we can view using the Apple TV greatly.

I hope someday someone finds this useful for their own similar setup.

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