PODCASTPARSER(1)

πŸ“¦
version 0.6.10 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu questing

✨ NAME ✨

okay so bestie, meet podcastparser β€” also known as podcastparser Documentation. πŸ’– It’s a simple and fast podcast feed parser library in Python. The two primary users of the library are the gPodder Podcast Client and the gpodder.net web service. No cap.

The following feed types are supported:

  • Really Simple Syndication (RSS 2.0)
  • Atom Syndication Format (RFC 4287)

The following specifications are supported:

  • Paged Feeds (RFC 5005)
  • Podlove Simple Chapters
  • Podcast Index Podcast Namespace

These formats only specify the possible markup elements and attributes. We recommend that you also read the Podcast Feed Best Practice guide if you want to optimize your feeds for best display in podcast clients. ✨

Where times and durations are used, the values are expected to be formatted either as seconds or as RFC 2326 Normal Play Time (NPT). πŸ•°οΈ

import podcastparser
import urllib.request

feedurl = 'http://example.com/feed.xml'

parsed = podcastparser.parse(feedurl, urllib.request.urlopen(feedurl))

# parsed is a dict
import pprint
pprint.pprint(parsed)

For both RSS and Atom feeds, only a subset of elements (those that are relevant to podcast client applications) is parsed. This section describes which elements and attributes are parsed and how the contents are interpreted/used. πŸ‘‘


πŸ“» RSS πŸ“»

  • rss@xml:base β€” Base URL for all relative links in the RSS file. It’s giving β€œanchor everything here,” fr fr. πŸ¦‹
  • rss/channel β€” Podcast. The whole channel vibe.
  • rss/channel/title β€” Podcast title (whitespace is squashed). Extra spaces? Gone. πŸ’…
  • rss/channel/link β€” Podcast website.
  • rss/channel/description β€” Podcast description (whitespace is squashed).
  • rss/channel/image/url β€” Podcast cover art. πŸŽ€
  • rss/channel/itunes:image β€” Podcast cover art (alternative).
  • rss/channel/itunes:type β€” Podcast type (whitespace is squashed). One of β€˜episodic’ or β€˜serial’. Those are the only options, bestie.
  • rss/channel/itunes:keywords β€” Podcast keywords (whitespace is squashed).
  • rss/channel/atom:link@rel=payment β€” Podcast payment URL (e.g. Flattr). πŸ’Έ
  • rss/channel/generator β€” A string indicating the program used to generate the channel. (e.g. MightyInHouse Content System v2.3).
  • rss/channel/language β€” Podcast language.
  • rss/channel/itunes:author β€” The group responsible for creating the show.
  • rss/channel/itunes:owner β€” The podcast owner contact information. The <itunes:owner> tag information is for administrative communication about the podcast and isn’t displayed in Apple Podcasts. πŸ“¬
  • rss/channel/itunes:category β€” The show category information.
  • rss/channel/itunes:explicit β€” Indicates whether podcast contains explicit material. πŸ”₯
  • rss/channel/itunes:new-feed-url β€” The new podcast RSS Feed URL.
  • rss/channel/podcast:locked β€” If the podcast is currently locked from being transferred.
  • rss/channel/podcast:funding β€” Funding link for podcast.
  • rss/redirect/newLocation β€” The new podcast RSS Feed URL.
  • rss/channel/item β€” Episode. The main character of the feed, honestly. 🌟
  • rss/channel/item/guid β€” Episode unique identifier (GUID), mandatory. Do not skip this one, periodt. πŸ›‘
  • rss/channel/item/title β€” Episode title (whitespace is squashed).
  • rss/channel/item/link β€” Episode website.
  • rss/channel/item/description β€” Episode description. If it contains html, it’s returned as description_html. Otherwise it’s returned as description (whitespace is squashed). See Mozilla’s article Why RSS Content Module is Popular.
  • rss/channel/item/itunes:summary β€” Episode description (whitespace is squashed).
  • rss/channel/item/itunes:subtitle β€” Episode subtitled / one-line description (whitespace is squashed).
  • rss/channel/item/content:encoded β€” Episode description in HTML. Best source for description_html. πŸ‘‘
  • rss/channel/item/itunes:duration β€” Episode duration.
  • rss/channel/item/pubDate β€” Episode publication date.
  • rss/channel/item/atom:link@rel=payment β€” Episode payment URL (e.g. Flattr).
  • rss/channel/item/atom:link@rel=enclosure β€” File download URL (@href), size (@length) and mime type (@type).
  • rss/channel/item/itunes:image β€” Episode art URL. 🎨
  • rss/channel/item/media:thumbnail β€” Episode art URL.
  • rss/channel/item/media:group/media:thumbnail β€” Episode art URL.
  • rss/channel/item/media:content β€” File download URL (@url), size (@fileSize) and mime type (@type).
  • rss/channel/item/media:group/media:content β€” File download URL (@url), size (@fileSize) and mime type (@type).
  • rss/channel/item/enclosure β€” File download URL (@url), size (@length) and mime type (@type).
  • rss/channel/item/psc:chapters β€” Podlove Simple Chapters, version 1.1 and 1.2. Obsessed. πŸ’œ
  • rss/channel/item/psc:chapters/psc:chapter β€” Chapter entry (@start, @title, @href and @image).
  • rss/channel/item/itunes:explicit β€” Indicates whether episode contains explicit material.
  • rss/channel/item/itunes:author β€” The group responsible for creating the episode.
  • rss/channel/item/itunes:season β€” The season number of the episode.
  • rss/channel/item/itunes:episode β€” An episode number.
  • rss/channel/item/itunes:episodeType β€” The episode type. This flag is used if an episode is a trailer or bonus content.
  • rss/channel/item/podcast:chapters β€” The url to a JSON file describing the chapters. Only the url is added to the data as fetching an external URL would be unsafe. Safety first, bestie. πŸ›‘οΈ
  • rss/channel/item/podcast:person β€” A person involved in the episode, e.g. host, or guest.
  • rss/channel/item/podcast:transcript β€” The url for the transcript file associated with this episode. πŸ“

🌟 ATOM 🌟

okay so if it's an Atom feed instead of RSS, bestie, podcastparser has you covered too. here's every single element and attribute it handles, no skips:

  • atom:feed β€” the Podcast itself πŸ’–
  • atom:feed/atom:title β€” Podcast title (whitespace is squashed, so all the extra spaces get folded down to one)
  • atom:feed/atom:subtitle β€” Podcast description (whitespace is squashed here too)
  • atom:feed/atom:icon β€” Podcast cover art 🎨
  • atom:feed/atom:link@href β€” Podcast website
  • atom:feed/atom:entry β€” an Episode
  • atom:feed/atom:entry/atom:id β€” Episode unique identifier (GUID), and heads up: this one is mandatory
  • atom:feed/atom:entry/atom:title β€” Episode title (whitespace is squashed)
  • atom:feed/atom:entry/atom:link@rel=enclosure β€” File download URL (@href), size (@length) and mime type (@type)
  • atom:feed/atom:entry/atom:link@rel=(self|alternate) β€” Episode website
  • atom:feed/atom:entry/atom:link@rel=payment β€” Episode payment URL (e.g. Flattr) πŸ’Έ
  • atom:feed/atom:entry/atom:content β€” Episode description (in HTML or plaintext)
  • atom:feed/atom:entry/atom:published β€” Episode publication date πŸ—“οΈ
  • atom:feed/atom:entry/media:thumbnail β€” Episode art URL
  • atom:feed/atom:entry/media:group/media:thumbnail β€” Episode art URL
  • atom:feed/atom:entry/psc:chapters β€” Podlove Simple Chapters, version 1.1 and 1.2
  • atom:feed/atom:entry/psc:chapters/psc:chapter β€” Chapter entry (@start, @title, @href and @image)

and now… the library itself. the actual Python API. this is where it gets fun, bestie:

Simplified, fast RSS parser β€” that's the whole vibe of this thing, and it ate fr fr.

  • exception podcastparser.FeedParseError(msg, exception, locator) β€” Exception raised when asked to parse an invalid feed 😭

the whole point of this exception is that you can catch it without having to import the XML parsing library yourself. iconic convenience, honestly.

  • class podcastparser.PodcastHandler(url, max_episodes) β€” the handler class, and here's what's inside it:
    • characters(chars) β€” Receive notification of character data.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

  • endElement(name) β€” Signals the end of an element in non-namespace mode.

The name parameter contains the name of the element type, just as with the startElement event.

  • startElement(name, attrs) β€” Signals the start of an element in non-namespace mode.

The name parameter contains the raw XML 1.0 name of the element type as a string and the attrs parameter holds an instance of the Attributes class containing the attributes of the element.

  • class podcastparser.RSSItemDescription β€” okay so RSS 2.0 almost encourages you to put html content in item/description, but content:encoded is the better source of html content, and itunes:summary is known to contain the short textual description of the item. so it uses a heuristic to attribute text to either description or description_html, without overriding existing values. clever girl behavior πŸ’…
  • podcastparser.file_basename_no_extension(filename) β€” Returns filename without extension
>>> file_basename_no_extension('/home/me/file.txt')
'file'

>>> file_basename_no_extension('file')
'file'
  • podcastparser.is_html(text) β€” Heuristically tell if text is HTML

By looking for an open tag (more or less):

>>> is_html('<h1>HELLO</h1>')
True
>>> is_html('a < b < c')
False
  • podcastparser.normalize_feed_url(url) β€” Normalize and convert a URL. If the URL cannot be converted (invalid or unknown scheme), None is returned.

This will also normalize feed:// and itpc:// to http://.

>>> normalize_feed_url('itpc://example.org/podcast.rss')
'http://example.org/podcast.rss'

If no URL scheme is defined (e.g. "curry.com"), we will simply assume the user intends to add a http:// feed.

>>> normalize_feed_url('curry.com')
'http://curry.com/'

It will also take care of converting the domain name to all-lowercase (because domains are not case sensitive):

>>> normalize_feed_url('http://Example.COM/')
'http://example.com/'

Some other minimalistic changes are also taken care of, e.g. a ? with an empty query is removed:

>>> normalize_feed_url('http://example.org/test?')
'http://example.org/test'

Leading and trailing whitespace is removed 🌸

>>> normalize_feed_url(' http://example.com/podcast.rss ')
'http://example.com/podcast.rss'

Incomplete (too short) URLs are not accepted 🚫

>>> normalize_feed_url('http://') is None
True

Unknown protocols are not accepted 🚫

>>> normalize_feed_url('gopher://gopher.hprc.utoronto.ca/file.txt') is None
True
  • podcastparser.parse(url, stream, max_episodes=0) β€” Parse a podcast feed from the given URL and stream

Parameters

  • url – the URL of the feed. Will be used to resolve relative links
  • stream – file-like object containing the feed content
  • max_episodes – maximum number of episodes to return. 0 (default) means no limit

Returns

  • a dict with the parsed contents of the feed ✨
  • podcastparser.parse_length(text) β€” Parses a file length
>>> parse_length(None)
-1

>>> parse_length('0')
-1

>>> parse_length('unknown')
-1

>>> parse_length('100')
100
  • podcastparser.parse_pubdate(text) β€” Parse a date string into a Unix timestamp
>>> parse_pubdate('Fri, 21 Nov 1997 09:55:06 -0600')
880127706

>>> parse_pubdate('2003-12-13T00:00:00+02:00')
1071266400

>>> parse_pubdate('2003-12-13T18:30:02Z')
1071340202

>>> parse_pubdate('Mon, 02 May 1960 09:05:01 +0100')
-305049299

>>> parse_pubdate('')
0

>>> parse_pubdate('unknown')
0
  • podcastparser.parse_time(value) β€” Parse a time string into seconds

See RFC2326, 3.6 "Normal Play Time" (HH:MM:SS.FRACT)

>>> parse_time('0')
0
>>> parse_time('128')
128
>>> parse_time('00:00')
0
>>> parse_time('00:00:00')
0
>>> parse_time('00:20')
20
>>> parse_time('00:00:20')
20
>>> parse_time('01:00:00')
3600
>>> parse_time(' 03:02:01')
10921
>>> parse_time('61:08')
3668
>>> parse_time('25:03:30 ')
90210
>>> parse_time('25:3:30')
90210
>>> parse_time('61.08')
61
>>> parse_time('01:02:03.500')
3723
>>> parse_time(' ')
0
  • podcastparser.parse_type(text) β€” "normalize" a mime type
>>> parse_type('text/plain')
'text/plain'

>>> parse_type('text')
'application/octet-stream'

>>> parse_type('')
'application/octet-stream'

>>> parse_type(None)
'application/octet-stream'
  • podcastparser.remove_html_tags(html) β€” Remove HTML tags from a string and replace numeric and named entities with the corresponding character, so the HTML text can be displayed in a simple text view. so clean, so demure 🧚
  • podcastparser.squash_whitespace(text) β€” Combine multiple whitespaces into one, trim trailing/leading spaces
>>> squash_whitespace(' some           text  with a    lot of   spaces ')
'some text with a lot of spaces'
  • podcastparser.squash_whitespace_not_nl(text) β€” Like squash_whitespace, but don't squash linefeeds and carriage returns
>>> squash_whitespace_not_nl(' linefeeds\ncarriage\r  returns')
'linefeeds\ncarriage\r returns'

This is a list of podcast-related XML namespaces that are not yet supported by podcastparser, but might be in the future. manifesting for them πŸ™


πŸŽ€ CHAPTER MARKS πŸŽ€

  • rawvoice RSS: Rating, Frequency, Poster, WebM, MP4, Metamark (kind of chapter-like markers)
  • IGOR: Chapter Marks

πŸ’« OTHERS πŸ’«

  • libSYN RSS Extensions: contactPhone, contactEmail, contactTwitter, contactWebsite, wallpaper, pdf, background
  • Comment API: Comments to a given item (readable via RSS)
  • MVCB: Error Reports To Field (usually a mailto: link)
  • Syndication Module: Update period, frequency and base (for skipping updates)
  • Creative Commons RSS: Creative commons license for the content
  • Pheedo: Original link to website and original link to enclosure (without going through pheedo redirect)
  • WGS84: Geo-Coordinates per item 🌍
  • Conversations Network: Intro duration in milliseconds (for skipping the intro), ratings
  • purl DC Elements: dc:creator (author / creator of the podcast, possibly with e-mail address)
  • Tristana: tristana:self (canonical URL to feed)
  • Blip: Show name, show page, picture, username, language, rating, thumbnail_src, license
  • Index
  • Module Index
  • Search Page

πŸ’– AUTHOR πŸ’–

gPodder Team β€” absolute legends, we stan 🫢

2023, gPodder Team


and that's a wrap bestie!! this was version 0.6.10, dated Jun 11, 2023, and yes, the whole thing lives under PODCASTPARSER(1). go parse some feeds, you're gonna slay πŸ’…βœ¨

πŸ“¦ where this page comes from