Skip to content

Commit c117c56

Browse files
authored
Merge pull request #49 from CJxD/patch-1
Add rss/channel/itunes:summary handling
2 parents 909649e + 5817daf commit c117c56

File tree

8 files changed

+49
-0
lines changed

8 files changed

+49
-0
lines changed

doc/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ RSS
105105
**rss/channel/description**
106106
Podcast description (whitespace is squashed).
107107

108+
**rss/channel/itunes:summary**
109+
Podcast description (whitespace is squashed).
110+
108111
**rss/channel/image/url**
109112
Podcast cover art.
110113

podcastparser.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,25 @@ class PodcastAttr(Target):
7676
WANT_TEXT = True
7777

7878
def end(self, handler, text):
79+
if not self.overwrite and handler.get_podcast_attr(self.key):
80+
return
7981
handler.set_podcast_attr(self.key, self.filter_func(text))
8082

8183
class PodcastAttrList(Target):
8284
WANT_TEXT = True
8385

8486
def end(self, handler, text):
87+
if not self.overwrite and handler.get_podcast_attr(self.key):
88+
return
8589
handler.set_podcast_attr(self.key, self.filter_func(text).split(', '))
8690

8791

8892
class PodcastAttrType(Target):
8993
WANT_TEXT = True
9094

9195
def end(self, handler, text):
96+
if not self.overwrite and handler.get_podcast_attr(self.key):
97+
return
9298
value = self.filter_func(text)
9399
if value in ('episodic', 'serial'):
94100
handler.set_podcast_attr(self.key, value)
@@ -104,6 +110,8 @@ class PodcastAttrFromHref(Target):
104110
ATTRIBUTE = 'href'
105111

106112
def start(self, handler, attrs):
113+
if not self.overwrite and handler.get_podcast_attr(self.key):
114+
return
107115
value = attrs.get(self.ATTRIBUTE)
108116
if value:
109117
value = urlparse.urljoin(handler.base, value)
@@ -734,6 +742,7 @@ def parse_pubdate(text):
734742
'rss/channel/title': PodcastAttr('title', squash_whitespace),
735743
'rss/channel/link': PodcastAttrRelativeLink('link'),
736744
'rss/channel/description': PodcastAttr('description', squash_whitespace_not_nl),
745+
'rss/channel/itunes:summary': PodcastAttr('description', squash_whitespace_not_nl, overwrite=False),
737746
'rss/channel/podcast:funding': PodcastAttrFromUrl('funding_url'),
738747
'rss/channel/podcast:locked': PodcastAttrExplicit('import_prohibited'),
739748
'rss/channel/image/url': PodcastAttrRelativeLink('cover_url'),
@@ -845,6 +854,9 @@ def set_base(self, base):
845854
def set_podcast_attr(self, key, value):
846855
self.data[key] = value
847856

857+
def get_podcast_attr(self, key, default=None):
858+
return self.data.get(key, default)
859+
848860
def set_episode_attr(self, key, value):
849861
self.episodes[-1][key] = value
850862

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"title": "Example Feed",
3+
"description": "A podcast with a description field",
4+
"episodes": []
5+
}

tests/data/channel_description.rss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<rss>
2+
<channel>
3+
<title>Example Feed</title>
4+
<description>A podcast with a description field</description>
5+
</channel>
6+
</rss>

tests/data/channel_summary.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"title": "Example Feed",
3+
"description": "A podcast with a summary field",
4+
"episodes": []
5+
}

tests/data/channel_summary.rss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
2+
<channel>
3+
<title>Example Feed</title>
4+
<itunes:summary>A podcast with a summary field</itunes:summary>
5+
</channel>
6+
</rss>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"title": "Example Feed",
3+
"description": "A podcast with a description field",
4+
"episodes": []
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
2+
<channel>
3+
<title>Example Feed</title>
4+
<description>A podcast with a description field</description>
5+
<itunes:summary>A podcast with a summary field</itunes:summary>
6+
</channel>
7+
</rss>

0 commit comments

Comments
 (0)