30 Jun 2023

Spotify Podcast RSS Format

Notes on a recent project to go from blog posts with attached MP3 files to an RSS podcast feed ready for Spotify.

It’s common practice to deliver a feed of podcast episodes using RSS. This is convenient as most websites that are using a content management system (à la WordPress) already support generating such feeds for posts. We just need to make a few changes as want to include links to the audio files not the web pages.

What’s the format?

First of all, there’s no special format really for Spotify. It’s the iTunes RSS format (although we’ll come back to this later).

Here is an example in pseudo-PHP-code. I’m leading with this as it’s the thing I was most keen to see when starting out which proved surprisingly awkward to find. It’s effectively some overall podcast information at the top before episodes are listed within <item> tags.

You’ll likely want to use a HTTP header of: Content-Type: text/xml; charset=UTF-8.

<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>My Test Podcast</title>
    <link>https://mytestpodcast.com</link>
    <language>en-GB</language>
    <copyright><?php echo $YYYY; ?> My Test Podcast</copyright>

    <itunes:author><?php echo $author ?></itunes:author>
    <itunes:summary><?php echo $summary ?></itunes:summary>
    <description><?php echo $description ?></description>

    <itunes:owner>
      <itunes:name>My Test Podcast Ltd</itunes:name>
      <itunes:email>[email protected]</itunes:email>
    </itunes:owner>

    <itunes:image href="<?php echo $default_image; ?>" />

    <itunes:category text="<?php echo $category ?>">
      <itunes:category text="<?php echo $sub_category ?>"/>
    </itunes:category>

    <?php // Loop here for each episode ?>
    <item>
      <title><?php echo $episode_title; ?></title>

      <itunes:author><?php echo $episode_author; ?></itunes:author>
      <itunes:summary><?php echo $episode_summary; ?></itunes:summary>

      <itunes:image href="<?php echo $image_url; ?>" />
      <enclosure url="<?php echo $fileurl; ?>" length="<?php echo $filesize; ?>" type="audio/mpeg" />
      <itunes:duration><?php echo $duration ?></itunes:duration>

      <guid><?php echo $fileurl; ?></guid>

      <?php $dateformatstring = 'D, d M Y H:i:s O'; // Date formating for iTunes feed ?>
      <pubDate><?php echo date($dateformatstring, $show_date); ?></pubDate>

    </item>
    <?php // End loop ?>
  </channel>
</rss>

I needed to implement this in a WordPress/PHP environment. There is a really useful post on that specific scenario available from a 2015 CSS Tricks article, you’ll see my example block above is similar to theirs.

Audio Format

Ideally it’s MP3. 128kbps or greater is recommended.

Aside: Calculate the episode duration

The feed requires the audio file size and duration. File size is easy in PHP as we have filesize() as a built-in. Duration is a little harder.

Here’s the shortcut I ended up going with. If you know the file size (which we do) and you also know the bitrate you can estimate by multiplying the two values. e.g. a 3MB MP3 file at 128 kpbs is likely around 3 minutes long:

// Note the times 8, megabytes to kilobytes to kilobits
(3 * 1000 * 8) / 128 = 187 (seconds)

In my case the files are reliably 64kbps MP3 files. I did a few test runs and this seems perfectly good enough. If we didn’t know the bitrate or wanted an exact figure we’d have to read some values from the MP3 files themselves which I was trying to avoid to keep things simple and fast.

Image Format

Per episode images are optional. The channel image will be used by default.

Regarding format, these points are lifted straight from the Spotify docs:

  • Podcast images need to have a fully squared (1:1) aspect ratio.
  • Preferably they should always be delivered in the highest resolution available to allow for all Spotify screen sizes.
  • Accepted formats in order of preference are: TIFF, PNG or JPEG.

What are the available categories?

Apple provide a full list of categories (and sub categories).

Note that you don’t have to provide a category, although without it Spotify recommendations do not work.

More Resources

If you’re interested in an even deeper integration then check out the full Spotify Podcast specification document. The spec doc shows that the acceptable format is not just iTunes tags but elements of “[…] RSS 2.0, Apple iTunes, Dublin Core Metadata, and MRSS 1.5…”.

Podbase have a well designed and easy to use RSS podcast validation page which I found beneficial to sanity check feed changes.

Dev WordPress
Back to posts