LinuxDevCenter.com

oreilly.comSafari Books Online.Conferences.

We've expanded our Linux news coverage and improved our search! Search for all things Linux across O'Reilly!

Search
Search Tips

advertisement

Listen Print Discuss Subscribe to Linux Subscribe to Newsletters

Indie Podcasting with Open Source
Pages: 1, 2

Putting the Files Up

What makes an audio file a podcast? There isn't anything special about the actual file data. It's still an MP3 (or whatever format). What makes it special and what enables people to subscribe to your podcasts is the RSS (Really Simple Syndication, some would say) 2.00 feed. RSS 2.00 added the enclosure tag that makes the whole thing doable.



There are several easy ways to get your podcasts on the web. If you're already a blogger through one of the organized blogging sites, then most likely there's a section where you can simply upload your podcast files and your site will do the rest. Another easy alternative is to use something such as ourmedia.org, which is free and allows you to upload all kinds of video and audio files.

If you're rolling your own, there are a few things to know. (None of it is exactly headache material.)

The first task (assuming you already have web space) is to create a directory for the podcasts. At Mstation, it's podcast_files. You can then use the dircaster PHP script:

<? 
// DirCaster v0.4: Automatic iPodder RSS feed maker Written by Ryan King
// www.shadydentist.com id3 class from frummel No license or warrantee
// expressed, implied, enclosed, etc.

// Drop this script in a directory and it will generate an RSS feed suitable for
// iPodder, etc based off the MP3 files in that directory. To 'cast a new
// file, simply upload it to the directory containing this script.

// Feed information is based on id3 tags, requires PHP4 or better. 
//
// Note: Avoid spaces in your MP3 filenames to avoid ugly filenames coming out
// of iPodder

// Instructions
// 1. Place this file on a server with supports PHP4 or greater.
// 2. Place MP3 files to feed in the same directory, add new files at will
// 3. Point iPodder to the URL of this file.
// ex. http://www.mysite.com/podcast/dircaster.php
// 4. Set the following varibles to match your setup if you wish

// Maximum number of mp3s to offer in a feed
$maxFeed = 10;

//Title of feed/site    Used by iPodder for download subdirectory name
$titleTAG="Your page title";

//iPodder 1.0 seems to ignore everything below
//URL of site feed applies too
$linkTAG="http://your url";
//Description
$descriptionTAG="description";
//Feed language en-us = english USA
$languageTAG="en-us";
//Copyright for feed
$copyrightTAG="various";
//Your email address
$webMasterTAG="podcasts@wherever.org";
//Name of feed generator
$generatorTAG="dirCastv0.4";
// Time to live
$ttlTAG=60;

///////////////
// You should not need to edit anything below this point.
/////////////
// Main Code
///////////
header('Content-type: text/xml', true);
$rootMP3URL = "http://" . $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI];
$rootMP3URL =  substr($rootMP3URL, 0, strrpos ($rootMP3URL, "/")); // Trim off script name itself

print "<?xml version=\"1.0\"?>\n";
print "<rss version=\"2.0\">\n";
print"    <channel>\n";
print"        <title>$titleTAG</title>\n";
print"        <link>$linkTAG</link>\n";
print"        <description>$descriptionTAG</description>\n";
print"        <lastBuildDate>" . date("r") ."</lastBuildDate>\n";
print"        <language>$languageTAG</language>\n";
print"        <copyright>$copyrightTAG</copyright>\n";
print"        <generator>$generatorTAG</generator>\n";
print"        <webMaster>$webMasterTAG</webMaster>\n";
print"        <ttl>$ttlTAG</ttl>\n\n";

$dirArray = getDir(".");    // Get a list of the current directory
while (list($filename, $filedate) = each($dirArray)AND $maxFeed > 0) {
    $mp3file = new CMP3File;
    $mp3file->getid3 ($filename);
    print "<item>\n";
    echo ("<title>$mp3file->title</title>\n");
    echo ("<link>$rootMP3URL/". htmlentities(str_replace(" ", "%20", $filename)) ."</link>\n");
    echo ("<description>$mp3file->title - $mp3file->album - $mp3file->artist</description>\n");
    echo ("<pubDate>".date("r",$filedate)."</pubDate>\n");
    echo ("<enclosure url=\"".htmlentities($rootMP3URL)."/". htmlentities(str_replace(" ", "%20", $filename)) ."\" length=\"");
    echo filesize($filename);
    echo ("\" type=\"audio/mpeg\"/>\n");    // Training slash for XML
    print "</item>\n\n";
    $maxFeed--;
}

print "</channel>\n</rss>\n";

// Functions and Classes
function stripJunk ($text) {
// Strip non-text characters
    for ($c=0; $c<strlen($text); $c++) {
        if (ord($text[$c]) >= 32 AND ord($text[$c]) <= 122)
            $outText.=$text[$c];
    }
    return $outText;
}

class CMP3File {
    //properties
    var $title;
    var $artist;
    var $album;
    var $year;
    var $comment;
    var $genre;
    
    function getid3 ($file)
    { // read the ID3 or ID3v2 tag from an MP3 file
        if (file_exists($file))
        { //after verifying the file exists,
            $id_start = filesize($file) - 128;
            
            $fp = fopen($file, "r");
            fseek($fp, $id_start);
            $tag = fread($fp,3);
            if ($tag == "TAG")
            {
                $this->title    = stripJunk(trim(fread($fp, 30)));
                $this->artist    = stripJunk(trim(fread($fp, 30)));
                $this->album    = stripJunk(trim(fread($fp, 30)));
                $this->year        = stripJunk(trim(fread($fp, 4)));
                $this->comment    = stripJunk(trim(fread($fp, 30)));
                $this->genre    = stripJunk(trim(fread($fp, 1)));
                fclose($fp);
                return true;
            }
            else
            { // No ID3 tag
                  fclose($fp);
                return false;
            }
        } else //the file doesn't exist
            return false;
    }
}

function getDir($mp3Dir) {    
// Returns directory as array[file]=date in newest to oldest order
    $dirArray = array();
    $diskdir = "./$mp3Dir/";
    if (is_dir($diskdir)) {
        $dh = opendir($diskdir);
        while (($file = readdir($dh)) != false ) {
            if (filetype($diskdir . $file) == "file" && $file[0]  != ".") {
                if (strrchr(strtolower($file), ".") == ".mp3") {
                    $ftime = filemtime($mp3Dir."/".$file); 
                    $dirArray[$file] = $ftime;
                }
            }
        }
        closedir($dh);
    }
    asort($dirArray);
    $dirArray = array_reverse($dirArray);
    return $dirArray;
}

?>

If you put this in the files directory and head for http://my_url/podcast_files/dircaster.php, you will find a genuine RSS 2.00 feed that people can subscribe to.

The resulting tags that are sent to a browser might look like the following:

<rss version="2.0">

    <channel>
<title>Mstation mmm podcasts</title>
<link>URL</link>
<description>Mstation Podcasts</description>
<lastBuildDate>Mon, 10 Apr 2006 12:01:12 +0100</lastBuildDate>
<language>en-us</language>
<copyright>various</copyright>
<generator>dirCastv0.4</generator>
<webMaster>podcasts*at*mstation.org</webMaster>
<ttl>60</ttl>

    <item>
<title/>

    <link>
http://mstation.org/podcast_files/mstation_dover_st_market.mp3
</link>
<description> -  -</description>
<pubDate>Mon, 20 Mar 2006 11:43:52 +0000</pubDate>
<enclosure url="http://mstation.org/podcast_files/mstation_dover_st_market.mp3" length="12715291" type="audio/mpeg"/>
</item>

At Mstation, we also have a separate Blosxom page where we discuss what the Mstation podcasts are about and how you can subscribe. We've used the Blosxom plugins enclosures, interpolate_fancy, and headlines to produce the layout and enable you to use the Mstation RSS 2.0 Podcast subscription feed with very little work on our part.

Blosxom handles the new m4v format for the TV iPod, while dircaster (at this stage, anyway) does not.

Once you have a subscription URL, you can also register it with iTunes or another feed syndicator such as Wikipedia list of podcast syndicators. On iTunes, you must create an account, but you don't actually have to buy anything to register your feed.

Good luck, and may your mind flow free!

John Littler is chief gopher for Mstation.org.


Return to the Linux DevCenter.


Have a question about John's suggestions or want to offer advice of your own? Here's where to do it.
You must be logged in to the O'Reilly Network to post a talkback.
Post Comment
Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • 1 last step!!
    2006-07-21 23:58:57  muzycmynd [Reply | View]

    I read your article and would like to know if there is a simpler way to create a podcast. I have both audacity and ardour. I got the music and idea ready to podcast but is there a progam that I can get for ubuntu 6.06 to on i386 ach to wrap my audio files in an rss to upload to my web sight. Or is bloxom the way to go. I'm not too informed on xml yet and did not understand you php4 diagram in the article.
    • 1 last step!!
      2006-07-22 02:10:40  john_l [Reply | View]

      Hi, The very easiest way to get things going is to go to somewhere like www.podomatic.com and start a new account (just name and email address required) type in the information relevant to the podcast, upload the mp3, and away you go. You'll end up with URL's like ...
      Your RSS Feed is: http://YourName.podOmatic.com/rss2.xml
      Your Podcast URL is: http://YourName.podOmatic.com
      Cheers
      John


Tagged Articles

Post to del.icio.us

This article has been tagged:

podcast

Articles that share the tag podcast:

Create Podcasts Using Your PC (47 tags)

How to Record a Podcast (44 tags)

How to Record a Podcast Interview (21 tags)

View All

opensource

Articles that share the tag opensource:

How Does Open Source Software Stack Up on the Mac? (90 tags)

ESR: "We Don't Need the GPL Anymore" (37 tags)

Calculating the True Price of Software (33 tags)

Ajax on Rails (24 tags)

An Introduction to Open Source Geospatial Tools (22 tags)

View All

podcasting

Articles that share the tag podcasting:

Create Podcasts Using Your PC (43 tags)

How to Record a Podcast (38 tags)

Audio Linkblogging (19 tags)

View All

linux

Articles that share the tag linux:

Managing Disk Space with LVM (74 tags)

Use Your Digital Camera with Linux (60 tags)

mdadm: A New Tool For Linux Software RAID Management (59 tags)

Asterisk: A Bare-Bones VoIP Example (43 tags)

View All

tutorial

Articles that share the tag tutorial:

Rolling with Ruby on Rails (1417 tags)

A Simpler Ajax Path (135 tags)

Ajax on Rails (88 tags)

Rolling with Ruby on Rails, Part 2 (66 tags)

Very Dynamic Web Interfaces (66 tags)

View All

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com