// Drop-it-in Podcast RSS Feed Generator written by Kiernan Holland // http://www.bl3nder.com/ // // Please Retain all the original comments so more people will // know where to get the newest update of "Drop-it-in". // // Usage: // Drop a mp3 file into the podcast directory, and pass // a link to this script to anyone you want to download your podcast feed. // // How to configure: // Go to the lines in this script labeled "TODO", // note that in the GVIM text editor, appearing hilighted // in yellow, that's why.. Best thing to do, is if you a // use "find" or use perl/vi/sed style regexp searches, // try the RSS feed out and tune until it shows up information // the way you like. I promise (if I can) that future versions // will be more obvious. // // How it works: // This script looks in that directory, extracts all the mp3 files // by looking at the file suffix. Then checks the modification time of the // files, and uses this to name and date the podcast entry. // And then it generates the RSS feed that can be used with a podcast // client like iTunes of ipodder, to download the mp3 files. // If there is no podcast, then it has a fancy way of handling that case, // you can even include a default "no podcast" message. // // Plans for the future: // Addition of meta file for more description, the purpose of using this // script is to accelerate the time to release. I also hope to use some // unix softlink polymorphism or something to allow this script to // distribute a number of feeds like odeo, itunes, and such.. But I hate // spinoff formats with a vengence, that's why I'm pushing an interst in object // based file formats versus straight XML. // // Copyright: Kiernan Holland (C) 2006 // Refer to the GNU Public License (at http://www.gnu.org/licenses/gpl.txt) // for information on Licensing. This source code is Open Source and // freely redistributable.. // $list = array(); // paths without the trailing slash $sans_serif_path = array(); $serif_path = array(); $p = &$sans_serif_path; //alias $s = &$serif_path; //alias //TODO: Directory that will contain THIS script. $p['local_dir'] = "."; //TODO: Sub-directory name that will host the podcast mp3 files. $p['podcasts_directory'] = "podcasts"; $p['relative_path_to_podcast'] = $p['local_dir'] . "/" . $p['podcasts_directory']; //TODO: Name of the apology "for no podcasts" file. $p['apology_file'] = "missing_podcast_apology.mp3"; $s['apology_file'] = false; $p['rel_apology_file'] = $p['relative_path_to_podcast'] . "/" . $p['apology_file']; $s['rel_apology_file'] = false; // unset this in the serif.. preg_match("/^(.*)\/[^\/]*$/",$_SERVER["PHP_SELF"],$matches); $p['path_to_me'] = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"]; $p['path_to_podcast'] = "http://" . $_SERVER["HTTP_HOST"] . $matches[1] . "/" . $p['podcasts_directory']; // serif paths are paths WITH the trailing slash.. $serif_path['path_to_me'] = false; // unset those that would not make sense. while(list($key,$value) = each($p)) { if (isset($serif_path[$key]) && (!$serif_path[$key])) unset($serif_path[$key]); else $serif_path[$key] = $value . "/"; } //print "
Sanserif\n" . print_r($sans_serif_path,1) . ""; //print "
Serif\n" . print_r($serif_path,1) . ""; $podcasts_directory_exists = &$sans_serif_path['relative_path_to_podcast']; $apology_file_found = false; $mime['mp3'] = "audio/mpeg"; if (!file_exists($podcasts_directory_exists)) { print "
\"$podcasts_directory_exists\" doesn't exist, please create a podcasts directory
";
exit;
} else {
if ($handle = opendir($podcasts_directory_exists)) {
while (false !== ($file = readdir($handle))) {
if (!is_dir($file) && ($outcome = preg_match("/^([^.]+)[.]([^.]*)$/",$file,$match)) && isset($mime[$match[2]])) {
//print $file . "
";
$rp_to_file = $podcasts_directory_exists . "/" . $file;
//print "
" . print_r($match,1) . ""; $time = filemtime($rp_to_file); //TODO: Change these messages to match your podcast.. // // handle naming for media files if (trim($file) == trim($p['apology_file'])) { //TODO: The Message that will appear if you have no podcasts $title = 'Pardon Us The Podcast Channel Is Currently Empty'; $descr = 'There Is currently no podcast files associated with this channel, check back later!'; $apology_file_found = trim($file); // location // TODO: } elseif(file_exists($file_description)) { // handle descriptions } else { $podcast_name = $file; if (preg_match("/([^.]*)[.][^.]*/",$file,$match)) { $podcast_name = $match[1]; } $podcast_name = preg_replace("/_/"," ",$podcast_name); $title = $podcast_name . " (Your Podcast Site's Name Here)"; $descr = "\"$podcast_name\" for date:" . date("r",$time); } $list[$file] = array( 'title' => $title, 'descr' => $descr, 'time' => $time, 'file' => $file, 'type' => $mime[$match[2]], 'size' => filesize($rp_to_file) ); } else { // unsupported file types and non-files if (is_dir($file)) { //print "found directory: $file
" . print_r($match,1) . ""; } else { //print "This should never happen: \"$file\"
" . print_r($list,1) . "
";
// Header determines how RSS file looks when you click on the link, comment
// these out, if you don't want any headers (link will appear as gunk)..
//
header('Content-type: application/rss+xml');
header('Content-Disposition: attachment; filename="your_podcasts_name_as_a_file_here.rss"');
print make_rss_entries($list);
function make_rss_entries($entry_list) {
$p = $GLOBALS['sans_serif_path']; //alias
$s = $GLOBALS['serif_path']; //alias
$where = $s['path_to_podcast'];
// HANDLE THE CASE WHERE THE ENTRY LIST IS 0, AN APOLOGY TAKES IT'S PLACE. TO RETAIN FEED INTEGRITY
//
$list = "";
// Make RSS Header
//
$hdr_title = "Title of your Podcast Feed";
$hdr_link = "Your Website Address Here";
$hdr_description = "Describe to the folks what your podcast is about";
$hdr_copy_right = "Your Copyright Information Here";
$hdr_last_build_date = "Fri, 10 Mar 2006 03:52:34 GMT";
if (is_array($entry_list)) $count = count($entry_list);
$header = "