Skip to content

Commit

Permalink
Merge pull request #97 from olikami/master
Browse files Browse the repository at this point in the history
Add missing iTunes tags

This fixes #96
  • Loading branch information
lkiesow authored Dec 21, 2023
2 parents c1c2859 + 2777ee9 commit f7f8cd7
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
5 changes: 5 additions & 0 deletions feedgen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ def main():
fg.podcast.itunes_summary('Lorem ipsum dolor sit amet, consectetur ' +
'adipiscing elit. Verba tu fingas et ea ' +
'dicas, quae non sentias?')
fg.podcast.itunes_type('episodic')
fe.podcast.itunes_author('Lars Kiesow')
fe.podcast.itunes_season(1)
fe.podcast.itunes_episode(1)
fe.podcast.itunes_title('First podcast episode')
fe.podcast.itunes_episode_type('full')
print_enc(fg.rss_str(pretty=True))

elif arg == 'torrent':
Expand Down
33 changes: 33 additions & 0 deletions feedgen/ext/podcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self):
self.__itunes_owner = None
self.__itunes_subtitle = None
self.__itunes_summary = None
self.__itunes_type = None

def extend_ns(self):
return {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
Expand Down Expand Up @@ -96,6 +97,10 @@ def extend_rss(self, rss_feed):
summary = xml_elem('{%s}summary' % ITUNES_NS, channel)
summary.text = self.__itunes_summary

if self.__itunes_type in ('episodic', 'serial'):
type = xml_elem('{%s}type' % ITUNES_NS, channel)
type.text = self.__itunes_type

return rss_feed

def itunes_author(self, itunes_author=None):
Expand Down Expand Up @@ -318,6 +323,34 @@ def itunes_summary(self, itunes_summary=None):
self.__itunes_summary = itunes_summary
return self.__itunes_summary

def itunes_type(self, itunes_type=None):
'''Get or set the itunes:type value of the podcast. This tag should
be used to indicate the type of your podcast.
The two values for this tag are "episodic" and "serial".
If your show is Serial you must use this tag.
Specify episodic when episodes are intended to be consumed without any
specific order. Apple Podcasts will present newest episodes first and
display the publish date (required) of each episode. If organized into
seasons, the newest season will be presented first - otherwise,
episodes will be grouped by year published, newest first.
Specify serial when episodes are intended to be consumed in sequential
order. Apple Podcasts will present the oldest episodes first and
display the episode numbers (required) of each episode. If organized
into seasons, the newest season will be presented first and
<itunes:episode> numbers must be given for each episode.
:param itunes_type: The type of the podcast
:returns: type of the pdocast.
'''
if itunes_type is not None:
if itunes_type not in ('episodic', 'serial'):
raise ValueError('Invalid value for type tag')
self.__itunes_type = itunes_type
return self.__itunes_type

_itunes_categories = {
'Arts': [
'Design', 'Fashion & Beauty', 'Food', 'Literature',
Expand Down
77 changes: 77 additions & 0 deletions feedgen/ext/podcast_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def __init__(self):
self.__itunes_order = None
self.__itunes_subtitle = None
self.__itunes_summary = None
self.__itunes_season = None
self.__itunes_episode = None
self.__itunes_title = None
self.__itunes_episode_type = None

def extend_rss(self, entry):
'''Add additional fields to an RSS item.
Expand Down Expand Up @@ -77,6 +81,22 @@ def extend_rss(self, entry):
if self.__itunes_summary:
summary = xml_elem('{%s}summary' % ITUNES_NS, entry)
summary.text = self.__itunes_summary

if self.__itunes_season:
season = xml_elem('{%s}season' % ITUNES_NS, entry)
season.text = str(self.__itunes_season)

if self.__itunes_episode:
episode = xml_elem('{%s}episode' % ITUNES_NS, entry)
episode.text = str(self.__itunes_episode)

if self.__itunes_title:
title = xml_elem('{%s}title' % ITUNES_NS, entry)
title.text = self.__itunes_title

if self.__itunes_episode_type in ('full', 'trailer', 'bonus'):
episode_type = xml_elem('{%s}episodeType' % ITUNES_NS, entry)
episode_type.text = self.__itunes_episode_type
return entry

def itunes_author(self, itunes_author=None):
Expand Down Expand Up @@ -242,3 +262,60 @@ def itunes_summary(self, itunes_summary=None):
if itunes_summary is not None:
self.__itunes_summary = itunes_summary
return self.__itunes_summary

def itunes_season(self, itunes_season=None):
'''Get or set the itunes:season value for the podcast episode.
:param itunes_season: Season number of the podcast epiosode.
:returns: Season number of the podcast episode.
'''
if itunes_season is not None:
self.__itunes_season = int(itunes_season)
return self.__itunes_season

def itunes_episode(self, itunes_episode=None):
'''Get or set the itunes:episode value for the podcast episode.
:param itunes_season: Episode number of the podcast epiosode.
:returns: Episode number of the podcast episode.
'''
if itunes_episode is not None:
self.__itunes_episode = int(itunes_episode)
return self.__itunes_episode

def itunes_title(self, itunes_title=None):
'''Get or set the itunes:title value for the podcast episode.
An episode title specific for Apple Podcasts. Don’t specify the episode
number or season number in this tag. Also, don’t repeat the title of
your show within your episode title.
:param itunes_title: Episode title specific for Apple Podcasts
:returns: Title specific for Apple Podcast
'''
if itunes_title is not None:
self.__itunes_title = itunes_title
return self.__itunes_title

def itunes_episode_type(self, itunes_episode_type=None):
'''Get or set the itunes:episodeType value of the item. This tag should
be used to indicate the episode type.
The three values for this tag are "full", "trailer" and "bonus".
If an episode is a trailer or bonus content, use this tag.
Specify full when you are submitting the complete content of your show.
Specify trailer when you are submitting a short, promotional piece of
content that represents a preview of your current show.
Specify bonus when you are submitting extra content for your show (for
example, behind the scenes information or interviews with the cast) or
cross-promotional content for another show.
:param itunes_episode_type: The episode type
:returns: type of the episode.
'''
if itunes_episode_type is not None:
if itunes_episode_type not in ('full', 'trailer', 'bonus'):
raise ValueError('Invalid value for episodeType tag')
self.__itunes_episode_type = itunes_episode_type
return self.__itunes_episode_type
10 changes: 10 additions & 0 deletions tests/test_extensions/test_podcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ def test_podcastItems(self):
fg.podcast.itunes_image('x.png')
fg.podcast.itunes_subtitle('x')
fg.podcast.itunes_summary('x')
fg.podcast.itunes_type('episodic')
assert fg.podcast.itunes_author() == 'Lars Kiesow'
assert fg.podcast.itunes_block() == 'x'
assert fg.podcast.itunes_complete() == 'no'
assert fg.podcast.itunes_explicit() == 'no'
assert fg.podcast.itunes_image() == 'x.png'
assert fg.podcast.itunes_subtitle() == 'x'
assert fg.podcast.itunes_summary() == 'x'
assert fg.podcast.itunes_type() == 'episodic'

# Check that we have the item in the resulting XML
ns = {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
Expand All @@ -78,6 +80,10 @@ def test_podcastEntryItems(self):
fe.podcast.itunes_order(1)
fe.podcast.itunes_subtitle('x')
fe.podcast.itunes_summary('x')
fe.podcast.itunes_season(1)
fe.podcast.itunes_episode(1)
fe.podcast.itunes_title('Podcast Title')
fe.podcast.itunes_episode_type('full')
assert fe.podcast.itunes_author() == 'Lars Kiesow'
assert fe.podcast.itunes_block() == 'x'
assert fe.podcast.itunes_duration() == '00:01:30'
Expand All @@ -87,6 +93,10 @@ def test_podcastEntryItems(self):
assert fe.podcast.itunes_order() == 1
assert fe.podcast.itunes_subtitle() == 'x'
assert fe.podcast.itunes_summary() == 'x'
assert fe.podcast.itunes_season() == 1
assert fe.podcast.itunes_episode() == 1
assert fe.podcast.itunes_title() == 'Podcast Title'
assert fe.podcast.itunes_episode_type() == 'full'

# Check that we have the item in the resulting XML
ns = {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
Expand Down

0 comments on commit f7f8cd7

Please sign in to comment.