hd-homerun-prime[Editors Note]  I actually wrote this blog back in June of 2014, but for whatever reason, never posted it.  It’s not complete, but I figured I’d share it with the Internet anyway.  I may come back and finish this at some point, but right now, I just don’t have the time.  Also the script below has evolved a bit over time, so I may update that to reflect what I have currently. 

A bit of a long story here, but recently I had decided to cut the cord on my TV service and called my local cable provider.  In my attempt to cancel only my TV service and not my internet service, they managed to talk me into a TV plan that was actually cheaper than what I was paying before and just a couple bucks more expensive than internet service alone.  That and a few other online streaming perks too.  I took the bait and they promptly sent me a new set top box so that I could watch more TV.

Unfortunately, when that new set top box arrived, I was promptly disappointed due to the fact that it was standard definition, slow and quite bulky in the entertainment center.  Obviously, there was no PVR capability either meaning it was only serving content to one TV in the house.  Not ideal really.  I started the search for something better.

As some of you know, I previously had setup SickBeard and SabNZBd for instructional purposes on this site before which is a perfectly capable system if you are OK with the legality of it – however it definitely gulps the bandwidth (or so I’ve heard).  So perhaps a better solution would be to record these shows from your own DVR box.  There are a lot of options for going this route, but I had previously come across something called the HDHomerun, which basically hooks up to your internal network, and your cable and will stream HD MPEG2 streams to whatever computer you wish.  It’s a really neat device.

Software

Let’s talk about software.  There is a lot to talk about here so let’s break it down into functionality.  Basically, what I want first and foremost is a PVR (or DVR, or whatever the heck you want to call it).  As a secondary project, I’d really love to have the capability to pipe live TV streams to my Roku.  I’ll save the secondary stuff for a future post (plus I haven’t had time to really tinker with this yet).

After a considerable amount of searching around for PVR solutions that run on Linux I found only two real potential options for me.  Because, as some of you may already know, I have an Ubuntu 12.04 server sitting on my network doing all kinds of NAS-like stuff, it just made sense to also use this as a backend PVR.  The two major players in this space are:

TVHeadend:  This solution is actually downright perfect for me because it is a pure web gui based solution with little overhead, easy (well not quite, as I would soon find out) setup, with a nice interface.  Unfortunately, after hours of banging my head against the wall getting this setup, I found that there is a fundamental issue how the Prime works that current prevents content from being accessed via the DVB drivers and TVHeadend.  While you can scan for stations perfectly well, the content just won’t come through because each channel is encrypted (not flagged for content protection, but digitally encrypted via the cable card).  As I understand it, there are potential fixes in the works for TVHeadend and the related DVBHDHomerun drivers/shim, but it could be some time before something gets developed.  I’m not holding my breath.

MythTV:  This is the solution that I eventually ended up with.  And it’s not without a fair amount of pain.  Quite frankly, I’m still trying to get this all tweaked and setup correctly.  For anyone who knows MythTV, it’s a pretty clumsy implementation of a PVR (apologies to all those people out there that work hard to bring this to the public).  Much of the pain that I experienced was self imposed, because of my unique setup, but there are some clear improvements to the usability of MythTV setup etc.

Getting MythTV setup and configured is a long process, but it’s definitely worth it once you get things going.  I had lot’s of help from various forums and contributors to the MythTV wiki – and piecing these together was a huge help to me.

With my configuration, it was important to me to be able to run MythTV headless with a Web based UI because I’m running this entirely on my Ubuntu 12.04 LTS headless NAS.  This is a bit difficult since the MythTV setup is graphical (X-Based) and requires X to be installed on the system.  Side note to MythTV developers: Why the heck do we need this to be graphical?  Can we just use a text based setup?  Many people, just like me, will thank you for making it easier for us to get the backend setup on a headless server.  Anyhow, there is a neat little workaround for this if you have another Linux machine on your network to get things running.  From that other machine do this from the terminal:

ssh -X mythtv@yourservername mythtv-setup

With this, no X-server is necessary on your headless box.  One caveat was that on my Ubuntu 13.10 box the screen is shifted such that the buttons on the bottom of the screen are obscured, also my mouse is not really visible.  It’s still usable though, with the arrow keys.

But before you get there, there are basic steps to setup.  Follow instructions here to get drivers for HDHomerun, setup and scan channels etc. and get all pre-requisites setup.  And, take my advice, sign up for schedules direct.  If you’re serious about this being set up properly, then spend the $25 and just do it.  Seriously, don’t try to cheap out on this one.  Time is money… and this will save you bundles of time.

My rig still had issues after getting things setup.  For one, my database password is broken.  So anytime I try to log in to mythtv-setup with the command above, it prompts me for a password.  Despite trying to setup a password manually, wiping and starting from scratch, I still can’t get a password setup correctly.  So after three incorrect password attempts it still let’s me into setup and I can still configure everything just fine.  As far as I can tell, the password is just an inconvenience.  Hopefully that doesn’t change someday and lock me out.

Mythweb was interesting to setup, since I already had a web server running on my system.  I ended up simply copying the Mythweb files over to my web server root and then everything seemed to just work.  Neat.

User Job Scripts

After getting MythTV up and running, I wanted to play with the user job scripts to try and do some fancy things. I wanted to try to run the commercial flagging, removal, transcoding, renaming and moving to Plex.

Again, after hours of much pain, I finally ended up with a script that will transcode, rename and move the transcoded copy of the file to Plex.  Why did I skip the commercial flagging?  It’s unreliable.  And with my limited testing, the flagging was not working well, skipping portions of the actual programming.  In order to actually cut the commercials, you need to use the mythtv transcoding tool which for some odd reason seemed to introduce errors in my files.  It was a bust from the start.  Maybe some day I will try it again, but for now, I’ve removed it from my script.

My script is currently pretty simple.  Here’s the general flow:

1. Creates a temporary directory under your recordings directory for the show it is about to transcode.

2. Uses Handbrake (could be modified to use ffmpeg or other transcoder, but I chose this out of simplicity) to transcode the original, very large MPEG2 format file to a smaller, more manageable H.264 mp4 file (which can be streamed to my Roku boxes).

3. Uses Filebot to rename the file and add the season number and episode number (sXXeXX).  I do this because it makes it much smoother for the last step to occur without issues.

4. Uses the Sickbeard script, sabtosickbeard.py, which is normally used by SabNZBd to organize your downloaded files into directories, and notify Sickbeard / Plex of the new show.  This will also rename your file… again.  You may be wondering why I use Filebot at all in step 3?  Well, the Sickbeard script seems to do better at recognizing the file if it already has a season number and episode number in the file name.  The script also cleans up for you by deleting the temporary folder after it’s moved the file.  Very nice!

What the script does NOT do.  My script doesn’t have any debug output.  My script does not remove the original file from MythTV recordings, or the database.  You’ll have to manually go delete things.  This is intentional, just in case things don’t go well, at least you have the backup.  Every so often you can manually clean up the recordings folder if you’re running low on space.


#!/bin/sh

#******************************************************************************
#******************************************************************************
#
# Myth > Handbrake (H.264) > Plex Script++ for MythTV
#
#******************************************************************************
#******************************************************************************
#
# Pre-requisites:
# HandBrakeCLI
# Filebot (portable edition)
# Sickbeard w/sabtoSickBeard.py
#
#
# Usage:
# 'mythtoplex.sh %DIR% %FILE% %CHANID% %STARTTIME% "%TITLE%" "%SUBTITLE%"'
#
# Description:
# My script is currently pretty simple. Here's the general flow:
#
# 1. Creates a temporary directory under your recordings directory for
# the show it is about to transcode.
#
# 2. Uses Handbrake (could be modified to use ffmpeg or other transcoder,
# but I chose this out of simplicity) to transcode the original, very
# large MPEG2 format file to a smaller, more manageable H.264 mp4 file
# (which can be streamed to my Roku boxes).
#
# 3. Uses Filebot to rename the file and add the season number and
# episode number (sXXeXX). I do this because it makes it much smoother
# for the last step to occur without issues.
#
# 4. Uses the Sickbeard script, sabtosickbeard.py, which is normally used
# by SabNZBd to organize your downloaded files into directories, and
# notify Sickbeard / Plex of the new show. This will also rename your
# file... again. You may be wondering why I use Filebot at all in step 3?
# Well, the Sickbeard script seems to do better at recognizing the file if
# it already has a season number and episode number in the file name. The
# script also cleans up for you by deleting the temporary folder after
# it's moved the file.
#
#******************************************************************************

#******************************************************************************
# Edit the following for your system
#******************************************************************************

TEMPDIR="/mnt/dionysus/mythtv/recordings/tmp" # Temporary directory for transcoding
SBSPATH="/home/parmeter/.sickbeard/autoProcessTV" # Path to sabToSickBeard.py
FBPATH="/home/parmeter/filebot" # Path to filebot.sh (from portable edition)
SED="/bin/sed" # Path to sed (Stream Editor)

#******************************************************************************
# Do not edit below this line
#******************************************************************************

VIDEODIR=$1 # %DIR% - Directory name of original file
FILENAME=$2 # %FILE% - Filename of original file
CHAN=$3 # %CHANID% - Channel ID for the recorded program - Reserved for future use
START=$4 # %STARTTIME% - Start time of the recorded program - Reserved for future use
TITLE=$5 # %TITLE% - Program Title
SUBTITLE=$6 # %SUBTITLE% - Program Subtitle

MYPID=$$ # Process ID for current script

echo "********************************************************"
echo "********************************************************"
echo " MythTV to Plex > Transcode and Organize"
echo "********************************************************"
echo "********************************************************"

# Adjust niceness of CPU priority for the current process
renice 19 $MYPID

# Convert space laden variables to have underscores instead (not used in lookup)
sed_str="s/[$\!@\/:;~#%^&*\`\(\)\"\'<>,.?]//g"
OTITLE=`echo $TITLE | $SED -e 's/[[ \t]]*/_/g' | $SED -e $sed_str`
OSUBTITLE=`echo $SUBTITLE | $SED -e 's/[[ \t]]*/_/g' | $SED -e $sed_str`
OUTFILE="$OTITLE-$OSUBTITLE.mp4"

# Make temporary directory TEMPDIR/OTITLE
mkdir $TEMPDIR/$OTITLE

echo "********************************************************"
echo "Transcoding, Converting to H.264 w/Handbrake"
echo "********************************************************"

HandBrakeCLI -i "$VIDEODIR/$FILENAME" -o "$TEMPDIR/$OTITLE/$OUTFILE" --audio 1 --aencoder copy:aac --audio-fallback faac --audio-copy-mask aac --preset="Universal"

# First Pass: FileBot
echo "********************************************************"
echo "Rename with FileBot... $OUTFILE"
echo "********************************************************"
# Filebot may fail if permissions are set correctly.
# 1. Make sure Filebot is executable by the mythtv user
# 2. Make sure Filebot's cache folder permissions are writable by the mythtv user
$FBPATH/./filebot.sh -rename "$TEMPDIR/$OTITLE/$OUTFILE" --format "{n}-{s00e00}-{t}" --db tvrage -non-strict

# Second Pass: SickBeard
echo "********************************************************"
echo "Sending to SickBeard for proper organization w/Plex"
echo "********************************************************"
# Set permissions so SickBeard doesn't fail (ymmv)
chmod -R 777 $TEMPDIR/$OTITLE/
# Execute script on the temporary directory
# This script may fail if permissions aren't set correctly
# 1. Make sure this script is executable by the mythtv user
# 2. Make sure that the source and destination folders are writable by the sickbeard script owner/user
python $SBSPATH/sabToSickBeard.py $TEMPDIR/$OTITLE/

echo "Done. Congrats!"

Was this post helpful?
  • Thanks 
  • Sort-of 
  • Not Helpful 

Leave a Reply

Your email address will not be published. Required fields are marked *