Introduction: MythTV / AppleTV2 Integration- Non Jailbreak Version

Picture of MythTV / AppleTV2 Integration- Non Jailbreak Version

I've been running MythTV in my home since late 2006, and have had great joy working with it over the years (started running it on Fedora Core 6- that's how long it's been!).  

So that's why when my wife got me an AppleTV2 for my birthday last year, I just had to integrate it into my MythTV environment.  The first thing I did was jailbreak the device, and installed XBMC.  Using the built-in DLNA server that MythTV includes, I was able to stream my recordings directly to my Apple TV2 with quite a bit of success.

While XBMC is a great product, using it on an Apple TV2 is not quite ideal- it requires a jailbreak, and it's a little odd moving back and forth between the Apple UI and the XBMC UI- which our family found ourselves doing quite a bit.  Also, Apple products seem to work best when you buy into their ecosystem- I know that sounds rather "sheep"-ish, but it's true.  

This instructable outlines how I am able to watch all of my MythTV shows on my AppleTV2, while staying "genius" friendly...

Step 1: My Environment- Overview

Picture of My Environment- Overview

This is my environment.  A brief description of how the setup works:

1) MythTV records a TV show
2) A custom job executes at the end of the recording which uses HandBrakeCLI to encode the video into AppleTV2 format.
3) Every 5 minutes, a powershell job executes on the Win7 VM.  This job does the following:
     a)  Uses the iTunes SDK to acquire an instance of the active iTunes "TV Shows" library.
     b)  Performs a query on MythConverg looking for all transcoded shows, and finds any not in iTunes yet.
     c)  Adds any missing shows from mythconverg into the TV Shows library
     d)  Looks through the TV Shows library, and removes any that are no longer in mythconverg

4) Wife enjoys Big Brother on our Apple TV2!

Note: All scheduling of new shows, and deletion of old shows happens through mythweb.

Step 2: Software Required

Nothing too crazy here- all software should be easily installed via the website of the application developer, or via your favorite Linux package manager.

1) A machine running Mythbackend
2) A Windows machine running iTunes (I only wrote the script in powershell)

Additional Software- Mythbackend Machine:
1) HandbrakeCLI
2) smbd

Additional Software- Windows Machine:
1) Windows powershell (if running WinXP only- included with Vista and above)
2) MySQL .NET Connector

Step 3: MythTV Setup

Picture of MythTV Setup

The main task at hand here is to setup the custom job and the cifs/samba file share for Win7 to use:

1) Get my source code here (*UPDATE* please download the 11 version for mythtv .26!)- read it, understand how it works- save it as: /home/mythtv/jobs/mythtv-transcode-atv2.sh
NOTE- you must put your mythconverg database username and password in here!

2) Make it executable: chmod a+x /home/mythtv/jobs/mythtv-transcode-atv2.sh

3) Configure the new job in mythtv-setup, in the "general" menu item- as shown in figure 1:
  Here is the full text shown in the picture: /home/mythtv/jobs/mythtv-transcode-atv2.sh "%DIR%/%FILE%" "%CHANID%" "%STARTTIMEISO%"
(UPDATE: For mythtv .26, use %STARTTIMEISOUTC% instead of %STARTTIMEISO%!!)

4) Save your changes in mythtv-setup, and exit.

5) Run mythfrontend, and set our new job to run automatically after new recordings.  This is done in the Setup->Video->General menu area (as shown in figure 2).  Save and exit mythfrontend

6) Create a new cifs share using your favorite configuration tool.  My share in smb.conf looks like (make it read/write):
   [recordings]
   comment = recordings
   path = /video
   valid users = mythtv
   public = no
   writable = yes
   printable = no

Note- this share needs to be read/write because iTunes will modify the video files to put metadata tags on them!

7) Make sure your mysql database is exposed to your internal network. A quick google search will help with that.

Step 4: Win7 Setup

Picture of Win7 Setup

Assuming you have all the prerequisite software installed, this should be simply setting up the scheduled task:

1)   Setup a new mapped network drive, as shown.  Doesn't matter which drive letter- I picked Y:\.

2)  Get my powershell script here- understand how it works.  Save it somewhere public on your Win7 machine.

2) In scheduled tasks, create a new task, making sure you execute powershell.exe as the action (I have posted pictures of the relevant parts of my configuration).  My powershell line is as such:
powershell.exe -command "c:\users\currentuserhere\desktop\SynciTunes.ps1 -recdir Y:\ -dbhost mythhost -dbuser dbuser -dbpass dbpassword"

3) In iTunes, turn on Home Sharing, as shown.

4) On your Apple TV2, also turn on Home Sharing, using the same Apple ID as in step 3.

5) Enjoy!

Step 5: Results/Final Comments

Picture of Results/Final Comments

Overall I'm quite happy with how this project turned out- I have all my mythtv shows accessible from my Apple TV2, complete with metadata (show title/subtitle/synopsis, etc). I also coded the recording date as part of the show's title in iTunes so I always know which order to watch the shows in.

*Update- I just got around to posting a picture of the results.  The date in parentheses is the original record date, which could be different than the "added" date, but normally are the same.

Potential Improvements:
1) I'd really like to not rely on a batch job on the Windows side to pull in shows.  Perhaps some sort of service could be written to be called on demand.

2) I'm not a fan of COM+, which is what the iTunes SDK is exposed as- i wish iTunes had a better API, or better yet, a DAEMONIZED version of iTunes!!  At least I could use powershell, which I AM a big fan of.

3) For a while, I put in a major hack in the form of a second powershell job that would parse out the handbrake logs and expose a status complete on the ATV2.  It did this by manipulating the name of a TV playlist in iTunes. Very hokey, but it would allow us to check the status of a transcode on demand from the ATV2.  I didn't include that here because it just didn't work all that well.

4) Sometimes shows do not delete immediately from iTunes, even after being removed via the SDK.  I'm not sure what that's about.  It eventually goes, but sometimes it takes a few runs of the sync job before they are gone.  Items do appear pretty much right away though, and that's what's important anyway.

5) Sometimes the sync script will not "find" a recording in iTunes (even though it's there), resulting it being added again.  It doesn't hurt anything, the show only shows up once in iTunes, but it slows the script down a bit.

Comments

timothyspirit (author)2013-01-16

sweet instructable thank you!

Computothought (author)2012-09-13

Cool. What gets me is there are all these streaming boxes based on open source that you dare not modify unless you want the wrath of the gods. Then there is Apple tv so proprietary and it is the one you can modify. Does not seem right.

cinntax (author)2012-08-03

Okay I took another look at this- and I think I know what the issue is.
Here's an example of what gets passed in from mythtv ($3):
2012-08-03T21:58:00

Here's what's in mythconverg as the start time field:
2012-08-03 21:58:00

So the ${3/T/ } is simply a bash construct to do a find/replace on the character 'T'.

Knowing this- i doubt that $3 will actually work- it may have cleared up your error, but I'm sure your database didn't get updated properly, so I would guess that your test recordings are not watchable at the moment (it's an easy fix however).

Here's the root of the problem though- the ${3/T/ } is a BASH construct, so you must actually be running BASH, and not another shell. On my machine, /bin/sh happens to be a symlink to bash, so that top line in the script is actually causing bash to run :).

Try this:
from the command line- run: whereis bash
on line 1- replace /bin/sh with the output from that (likely /bin/bash- so #!/bin/bash for example.)

I'll update the code to be /bin/bash instead of /bin/sh. Thanks- let me know if that fixes it!

BoxOfSnoo (author)cinntax2012-08-08

Aha, yup on Ubuntu /bin/sh is symlinked to /bin/dash, that probably caused the problem.

Thanks!

BoxOfSnoo (author)2012-08-03

I can't get the bash script to work, it dies at this line:

SHOWTIME=${3/T/ }

What's it do? Why wouldn't SHOWTIME=$3 work? It seems to do so on my tests.

cinntax (author)BoxOfSnoo2012-08-03

Thanks for trying it- I know it had something to do with formatting the date so the SQL query would work (sorry I wrote it a while ago). I'm out and about, but will investigate when I get home.

About This Instructable

8,026views

8favorites

More by cinntax:MythTV / AppleTV2 Integration- Non Jailbreak Version
Add instructable to: