ITunes integration

From MythTV Official Wiki
Revision as of 22:57, 20 December 2010 by Mpyne (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Wouldn't it be nice for your TV recordings to show up in iTunes in a way that makes it easy to copy them to your iPod/iPhone/iPad without having to hack around with iTunes or the device itself?

Well it turns out there is a very easy way of doing this, and it requires very little setup. Just make the recordings available as a podcast! Then all you have to do is to sync that podcast with your iDevice and everything will automatically keep your device up to date with the latest recordings and automatically delete the ones you have watched. Simple.


The 3 simple steps

Convert the recordings to iPod compatible .mp4 format

The first thing you have to do is convert your recordings from the file format that MythTV uses internally (.mpg) to files that an iPod will accept (.mp4). There is lots of advice on doing this on this wiki, so I suggest you have a look around. The short version is that you need to create a "user script" that runs after your show has been recorded which performs the conversion. You can then choose which shows to put in to iTunes by choosing whether to run the script or not when you set the show for recording.

NOTE: Make sure the .mp4 version of the file goes in to your recordings directory (i.e. the same one as the original .mpg file).

Add the podcast to MythWeb

Now you have the video files to send to iTunes, you need to alter MythWeb to make an iTunes compatible RSS podcast feed.

Replace the file Recorded.php which you will find in (if you are using Ubuntu, other distributions will vary but you should be able to find it if you hunt around enough) /var/www/mythweb/modules/tv/tmpl/rss with the following:

<?php
/**
 * Create a rss of the recorded programs.
 *
 * @url         $URL$
 * @date        $Date$
 * @version     $Revision$
 * @author      $Author$
 * @license     GPL
 *
 * @package     MythWeb
 * @subpackage  TV
 *
/**/

    $Feed = new FeedWriter(RSS2);
    $Feed->setTitle('MythWeb - Recorded Programs');
    $Feed->setLink(root_url);
    $Feed->setDescription('MythWeb - Recorded Programs');

    foreach ($All_Shows as $show) {
	$filename = basename($show->filename);
	$filename = preg_replace('/\..+$/', '.mp4', $filename);
	$filename = '/var/lib/mythtv/recordings/'. $filename;

	if (file_exists( $filename ) )
	{
      	    $item = $Feed->createNewItem();

            $item->setTitle($show->title.(strlen($show->subtitle) > 0 ? ' - '.$show->subtitle : ''));
            $item->setLink(root_url.'tv/detail/'.$show->chanid.'/'.$show->recstartts);
            $item->setDate($show->starttime);
            $item->setDescription($show->description);
	    $item->setEncloser($show->url.'.mp4',filesize( $filename ), 'video/mp4' );
            $Feed->addItem($item);
	}
    }

    $Feed->generateFeed();


Add the podcast to iTunes

Finally you can now add tell iTunes about the podcast. Point your favourite web-browser at your MythTV server and browse to the "Recordinged Programs". Scroll to the bottom of the page and you will find a "RSS" link. Click on it.

If all has gone well then you will see the recorded program information summarised and some indication of the video content (depending on which browser you have used, you should be able to click on it and see the show).

Copy the URL from the browser, and head on over to iTunes. Go to Advanced-> Subscribe to Podcast. Enter the URL in the dialogue and hit "OK". (Make sure it starts with http:// and not feed:// ).

Now you should see the shows loaded in to iTunes. Plug in your iDevice and find the "Podcast" settings for it. Select "Sync Podcast" and then select the mythweb podcast you have just added.

There are various options for determining how many show will be downloaded to iTunes and also how many will be sync'ed to your iDevice, I leave it to you to explore.

Troubleshooting

  • Check the Recorded.php script has the correct directory for your recorded TV as I had to hard-code it.
  • Check you actually have the .mp4 files in your recordings directory, and that Apache has read-access to them.
  • Make sure you create .mp4 files and *not* .mov files as MythWeb already has the capability of serving these files.
  • If iTunes is giving you an error it is probably because you are recording a show with an & in the name (like Law & Order) and there is a bug in MythWeb which makes the XML invalid.