3G Podcast Hack

One of the most interesting new features in iPhone Firmware 2.2 is the ability to download podcast episodes without a computer. Unfortunately Apple restricts this to episodes below 10 MB.

Well, we found a workaround for our own Podcast and would like to share the solution with you. Please notice that this solution is implemented on the podcast server. The Client (iPhone) remains untouched. So this article is mostly for those producing or hosting their own Podcast.

F4FA5592-9247-460F-9B8A-2C991F7A069E.jpg

iTunes telling you „Preparing download…“ Wait. No really, just wait!

The trick is basically not telling the iPhone how big the file is. Just leave out the Content-Length Response Header or set it to „-1“. For this to work the filename needs to remain untouched. In theory this should be an easy task with mod_headers. Unfortunately our apache ignored everything which had to do with the content-length. If you find a working solution please tell us.

So what we implemented instead is a combination of mod_rewrite and a little php script.

The downsize of this solution is that the Client can’t tell you any progress while downloading. The iPhone will just tell you that it is preparing the download while actually downloading. Please note that with the solution below nothing will change for your iTunes or Mobile-iTunes if on WiFi. Everything will work as used (including progress bar).

Example Implementation:

Apache-Directives (.htaccess)

# Check if the Client is an iPhone on the cellular network.
SetEnvIf X-Apple-Connection-Type "^3G" iphone_wo_wifi=1
SetEnvIf X-Apple-Connection-Type "^2G" iphone_wo_wifi=1

# Redirect the request to our php file 
# (if the client is an iPhone without wifi)
RewriteEngine on
RewriteBase /Podcast/
RewriteCond  %{ENV:iphone_wo_wifi}  ^1$
RewriteRule  ^(.*)\.m4a$ small_episode_fake.php?filename=$1
PHP File (small_episode_fake.php)

<?php
// THIS IS A VERY DANGEROUS PHP FILE!
// IF YOU DO NOT KNOW WHAT YOU ARE DOING.... LEAVE IT.
// THIS FILE GIVES USERS FILES RESIDING ON YOUR SERVER...
// IF YOU DON'T TAKE CARE THIS MAY BE __ANY__ FILE
// WHERE ARE YOUR FILES ..
$podcastdir = "/var/www/kyri0s.de/htdocs/Podcast/";
$filename = basename($_GET['filename']);
// Long time no php.. i'm kinda paranoid since I don't
// know if basename() is safe enough.

// YOU NEED TO CHANGE THE FOLLOWING LINE. Replace 
// "iPhoneBlog\.de_Shortcast_\d+" with a pattern matching 
// your episodes.

// Example: 
// if(preg_match('/^GarageBand_Episode_\d+$/',$filename))
//          This would match:
//            GarageBand_Episode_1, 
//            GarageBaned_Episode_2,
//            etc..

// see http://en.wikipedia.org/wiki/Regular_expressions
// on matching rules
if(preg_match('/^iPhoneBlog\.de_Shortcast_\d+$/',$filename))
{
        header('Content-type: audio/mpeg');
        header('Content-Length: -1');
        readfile($podcastdir . $filename . '.m4a');
}
?>