Create a Podcast with Dato

Here’s a Ruby Builder script to create a podcast feed using Dato. It’s super simple but took me some time to review the various standards and get it validating in iTunes Connect. Enjoy!

The only thing that doesn’t currently work is the episode.audio.duration value, as Dato currently doesn’t calculate this for audio files. I hope this is added soon, as it’s great to have a site’s podcast all in the same CMS and with easy static hosting of the feed.

xml.instruct! :xml, version: "1.0"

rss_attributes = {
  "version" => "2.0",
  "xmlns:dc" => "http://purl.org/dc/elements/1.1/",
  "xmlns:sy" => "http://purl.org/rss/1.0/modules/syndication/",
  "xmlns:atom" => "http://www.w3.org/2005/Atom",
  "xmlns:rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
  "xmlns:content" => "http://purl.org/rss/1.0/modules/content/",
  "xmlns:itunes" => "http://www.itunes.com/dtds/podcast-1.0.dtd",
  "xmlns:media" => "http://search.yahoo.com/mrss/"
}

xml.rss rss_attributes do
  xml.channel do
    xml.title podcast.title
    xml.language "en-GB"
    xml.description podcast.description

    xml.link podcast_feed_url
    xml.atom :link, href: podcast_feed_url, rel: "self", type: "application/rss+xml"

    xml.itunes :author, podcast.author.name
    xml.itunes :subtitle, podcast.subtitle
    xml.itunes :explicit, "clean"
    xml.itunes :category, text: podcast.category
    xml.itunes :image, href: podcast.artwork.url(w: 1500, h: 1500, fit: :crop)

    xml.itunes :owner do
      xml.itunes :name, podcast.owner.name
      xml.itunes :email, podcast.email
    end

    podcast.episodes.each do |episode|
      xml.item do
        xml.title episode.title
        xml.description episode.description
        xml.pubDate episode.date.rfc2822
        xml.guid podcast_episode_url(episode), isPermaLink: true
        xml.link podcast_episode_url(episode)

        xml.itunes :author, episode.author.name
        xml.itunes :subtitle, episode.subtitle
        xml.itunes :duration, episode.audio.duration
        xml.itunes :image, href: episode.artwork.url(w: 1500, h: 1500, fit: :crop)
        xml.itunes :explicit, "clean"

        xml.enclosure url: episode.audio.url, length: episode.audio.size, type: "audio/mpeg"
        xml.media :content, url: episode.audio.url, type: "audio/mpeg"
      end
    end
  end
end
1 Like

Thank you very much for this!!! :slight_smile: