Friday, January 20, 2006

Changing FeedCreator.class.php for Podcasting

As I mentioned in my Podcasting HowTo, I used Kai Blankenhorn's FeedCreator.class.php as the basis of my podcasting feed. In this posting I will detail my additions to his code to support podcasting and iTunes.

You may download the final file here

First, at line 31, I updated the change log:

v1.7.2-iTunes
added support for iTunes tags
v1.7.2-podcast
added support for podcast (added enclosure)
made the Item category be an Array as you are allowed to specify
multiple category elements in the RSS spec

Then, at what becomes line 173 (after the changelog changes), I added
these classes:

/**
* Version string.
**/
define("FEEDCREATOR_VERSION", "FeedCreator 1.7.2-iTunes");
/**
* An Enclosure is a part of an Item
*
* @author Steven Pothoven <steven@pothoven.net>
* @since 1.7.2-podcast
*/
class Enclosure {
/**
* Attributes of an enclosure
*/
var $url, $length, $type = "audio/mpeg";
}
/**
* iTunes extensions to RSS 2.0
*
* @author Steven Pothoven <steven@pothoven.net>
* @since 1.7.2-iTunes
*/
class iTunes {
/**
* This tag can only be populated using iTunes specific categories.
*/
var $category, $subcategory;
/**
* This tag should be used to note whether or not your Podcast contains explicit material.
* There are 2 possible values for this tag: Yes or No
*/
var $explicit;
/*
* At the Channel level, this tag is a short description that provides general information about the Podcast. It will appear next to your Podcast as users browse through listings of Podcasts
* At the Item level, this tag is a short description that provides specific information for each episode.
* Limited to 255 characters or less, plain text, no HTML
*/
var $subtitle;
/*
* At the Channel level, this tag is a long description that will appear next to your Podcast cover art when a user selects your Podcast.
* At the Item level, this tag is a long description that will be displayed in an expanded window when users click on an episode.
* Limited to 4000 characters or less, plain text, no HTML
*/
var $summary;
/*
* At the Channel level this tag contains the name of the person or company that is most widely attributed to publishing the Podcast and will be displayed immediately underneath the title of the Podcast.
* If applicable, at the item level, this tag can contain information about the person(s) featured on a specific episode.
*/
var $author;
/*
* This tag is for informational purposes only and will allow users to know the duration prior to download
* The tag is formatted: HH:MM:SS
*/
var $duration;
/*
* This tag allows users to search on text keywords
* Limited to 255 characters or less, plain text, no HTML, words must be separated by spaces
*/
var $keywords;
/*
* This tag contains the e-mail address that will be used to contact the owner of the Podcast for communication specifically about their Podcast on iTunes.
* Required element specifying the email address of the owner.
*/
var $owner_email;
/*
* Optional element specifying the name of the owner.
*/
var $owner_name;
/*
* This tag specifies the artwork for the Channel and Item(s). This artwork can be larger than the maximum allowed by RSS.
* Preferred size: 300 x 300 at 72 dpi
* Minimum size: 170 pixels x 170 pixels square at 72 dpi
* Format: JPG, PNG, uncompressed
*/
var $image;
/*
* This tag is used to block a podcast or an episode within a podcast from being posted to iTunes. Only use this tag when you want a podcast or an episode to appear within the iTunes podcast directory.
*/
var $block;
}


In the FeedItem class I added these lines at the new line 283:

/**
* Support for attachments
*/
var $enclosure;
/**
* Support for iTunes
*/
var $itunes;


In the _setFormat function, I added a new case at the new line 491:

case "PODCAST":
$this->_feed = new PodcastCreator();
break;


In the createFeed function, I added the iTunes extentions at line
1102:

/* iTunes add iTunes specific tags */
if ($this->itunes!="") {
if ($this->itunes->category!="") {
$feed.= " <itunes:category text=\"".htmlspecialchars($this->itunes->category)."\">\n";
if ($this->itunes->subcategory!="") {
$feed.= " <itunes:category text=\"".htmlspecialchars($this->itunes->subcategory)."\"/>\n";
}
$feed.= " </itunes:category>\n";
}
if ($this->itunes->explicit!="") {
$feed.= " <itunes:explicit>".$this->itunes->explicit."</itunes:explicit>\n";
}
if ($this->itunes->subtitle!="") {
$feed.= " <itunes:subtitle>".htmlspecialchars($this->itunes->subtitle)."</itunes:subtitle>\n";
}
if ($this->itunes->summary!="") {
$feed.= " <itunes:summary>".htmlspecialchars($this->itunes->summary)."</itunes:summary>\n";
}
if ($this->itunes->author!="") {
$feed.= " <itunes:author>".htmlspecialchars($this->itunes->author)."</itunes:author>\n";
}
if ($this->itunes->keywords!="") {
$feed.= " <itunes:keywords>".htmlspecialchars($this->itunes->keywords)."</itunes:keywords>\n";
}
if ($this->itunes->owner_email!="") {
$feed.= " <itunes:owner>\n";
$feed.= " <itunes:email>".$this->itunes->owner_email."</itunes:email>\n";
if ($this->itunes->owner_name!="") {
$feed.= " <itunes:name>".$this->itunes->owner_name."</itunes:name>\n";
}
$feed.= " </itunes:owner>\n";
}
if ($this->itunes->image!="") {
$feed.= " <itunes:link rel=\"image\" type=\"image/jpeg\" href=\"".$this->itunes->image."\">[image]</itunes:link>\n";
}


and additional iTunes and podcast extensions at line 1154:

/* podcasts add the enclosure element */
if ($this->items[$i]->enclosure!="") {
$feed.= " <enclosure url=\"".str_replace(" ", "%20", htmlspecialchars($this->items[$i]->enclosure->url)). "\" length=\"".htmlspecialchars($this->items[$i]->enclosure->length). "\" type=\"".htmlspecialchars($this->items[$i]->enclosure->type). "\"/>\n";
}
/* iTunes add iTunes specific tags */
if ($this->items[$i]->itunes!="") {
if ($this->items[$i]->itunes->category!="") {
$feed.= " <itunes:category text=\"".htmlspecialchars($this->items[$i]->itunes->category)."\">\n";
if ($this->items[$i]->itunes->subcategory!="") {
$feed.= " <itunes:category text=\"".htmlspecialchars($this->items[$i]->itunes->subcategory)."\"/>\n";
}
$feed.= " </itunes:category>\n";
}
if ($this->items[$i]->itunes->explicit!="") {
$feed.= " <itunes:explicit>".$this->items[$i]->itunes->explicit."</itunes:explicit>\n";
}
if ($this->items[$i]->itunes->subtitle!="") {
$feed.= " <itunes:subtitle>".htmlspecialchars($this->items[$i]->itunes->subtitle)."</itunes:subtitle>\n";
}
if ($this->items[$i]->itunes->summary!="") {
$feed.= " <itunes:summary>".htmlspecialchars($this->items[$i]->itunes->summary)."</itunes:summary>\n";
}
if ($this->items[$i]->itunes->author!="") {
$feed.= " <itunes:author>".htmlspecialchars($this->items[$i]->itunes->author)."</itunes:author>\n";
}
if ($this->items[$i]->itunes->keywords!="") {
$feed.= " <itunes:keywords>".htmlspecialchars($this->items[$i]->itunes->keywords)."</itunes:keywords>\n";
}
if ($this->items[$i]->itunes->duration!="") {
$feed.= " <itunes:duration>".$this->items[$i]->itunes->duration."</itunes:duration>\n";
}
if ($this->items[$i]->itunes->image!="") {
$feed.= " <itunes:link rel=\"image\" type=\"image/jpeg\" href=\"".$this->items[$i]->itunes->image."\">[image]</itunes:link>\n";
}


Finally, I added the PodcastCreator class at line 1235:

/**
* PodcastCreator is a FeedCreator that implements Podcast
*
* @see http://backend.userland.com/rss
* @since 1.7.2-podcast
* @author Steven Pothoven <steven@pothoven.net>
*/
class PodcastCreator extends RSSCreator20 {
function PodcastCreator() {
parent::_setRSSVersion("2.0");
parent::_setXMLNS("itunes=\"http://www.itunes.com/DTDs/Podcast-1.0.dtd\"");
}
}

2 comments:

Casey said...

I would like to download the feedcreator class file, but I keep getting a 404 error...

Steven Pothoven said...

Sorry, I moved the file but didn't update the link. It should work now.