diff --git a/doc/index.rst b/doc/index.rst index 2f0e449..46e4d78 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -105,6 +105,9 @@ RSS **rss/channel/description** Podcast description (whitespace is squashed). +**rss/channel/itunes:summary** + Podcast description (whitespace is squashed). + **rss/channel/image/url** Podcast cover art. diff --git a/podcastparser.py b/podcastparser.py index 5ad0e86..3d0430e 100644 --- a/podcastparser.py +++ b/podcastparser.py @@ -76,12 +76,16 @@ class PodcastAttr(Target): WANT_TEXT = True def end(self, handler, text): + if not self.overwrite and handler.get_podcast_attr(self.key): + return handler.set_podcast_attr(self.key, self.filter_func(text)) class PodcastAttrList(Target): WANT_TEXT = True def end(self, handler, text): + if not self.overwrite and handler.get_podcast_attr(self.key): + return handler.set_podcast_attr(self.key, self.filter_func(text).split(', ')) @@ -89,6 +93,8 @@ class PodcastAttrType(Target): WANT_TEXT = True def end(self, handler, text): + if not self.overwrite and handler.get_podcast_attr(self.key): + return value = self.filter_func(text) if value in ('episodic', 'serial'): handler.set_podcast_attr(self.key, value) @@ -104,6 +110,8 @@ class PodcastAttrFromHref(Target): ATTRIBUTE = 'href' def start(self, handler, attrs): + if not self.overwrite and handler.get_podcast_attr(self.key): + return value = attrs.get(self.ATTRIBUTE) if value: value = urlparse.urljoin(handler.base, value) @@ -732,6 +740,7 @@ def parse_pubdate(text): 'rss/channel/title': PodcastAttr('title', squash_whitespace), 'rss/channel/link': PodcastAttrRelativeLink('link'), 'rss/channel/description': PodcastAttr('description', squash_whitespace_not_nl), + 'rss/channel/itunes:summary': PodcastAttr('description', squash_whitespace_not_nl, overwrite=False), 'rss/channel/podcast:funding': PodcastAttrFromUrl('funding_url'), 'rss/channel/podcast:locked': PodcastAttrExplicit('import_prohibited'), 'rss/channel/image/url': PodcastAttrRelativeLink('cover_url'), @@ -843,6 +852,9 @@ def set_base(self, base): def set_podcast_attr(self, key, value): self.data[key] = value + def get_podcast_attr(self, key, default=None): + return self.data.get(key, default) + def set_episode_attr(self, key, value): self.episodes[-1][key] = value diff --git a/tests/data/channel_description.json b/tests/data/channel_description.json new file mode 100644 index 0000000..296e677 --- /dev/null +++ b/tests/data/channel_description.json @@ -0,0 +1,5 @@ +{ + "title": "Example Feed", + "description": "A podcast with a description field", + "episodes": [] +} diff --git a/tests/data/channel_description.rss b/tests/data/channel_description.rss new file mode 100644 index 0000000..36b15d3 --- /dev/null +++ b/tests/data/channel_description.rss @@ -0,0 +1,6 @@ + + + Example Feed + A podcast with a description field + + diff --git a/tests/data/channel_summary.json b/tests/data/channel_summary.json new file mode 100644 index 0000000..cf16e53 --- /dev/null +++ b/tests/data/channel_summary.json @@ -0,0 +1,5 @@ +{ + "title": "Example Feed", + "description": "A podcast with a summary field", + "episodes": [] +} diff --git a/tests/data/channel_summary.rss b/tests/data/channel_summary.rss new file mode 100644 index 0000000..e6340ae --- /dev/null +++ b/tests/data/channel_summary.rss @@ -0,0 +1,6 @@ + + + Example Feed + A podcast with a summary field + + diff --git a/tests/data/channel_summary_and_description.json b/tests/data/channel_summary_and_description.json new file mode 100644 index 0000000..296e677 --- /dev/null +++ b/tests/data/channel_summary_and_description.json @@ -0,0 +1,5 @@ +{ + "title": "Example Feed", + "description": "A podcast with a description field", + "episodes": [] +} diff --git a/tests/data/channel_summary_and_description.rss b/tests/data/channel_summary_and_description.rss new file mode 100644 index 0000000..ac9efcc --- /dev/null +++ b/tests/data/channel_summary_and_description.rss @@ -0,0 +1,7 @@ + + + Example Feed + A podcast with a description field + A podcast with a summary field + +