Skip to content

Commit

Permalink
Merge pull request #110 from tobinus/feat/episode-type-#103
Browse files Browse the repository at this point in the history
Implement Episode.episode_type
  • Loading branch information
tobinus authored Dec 9, 2019
2 parents 40e7af4 + 230dd61 commit 903a4bf
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
1 change: 1 addition & 0 deletions podgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals
from builtins import *

from .constants import EPISODE_TYPE_BONUS, EPISODE_TYPE_FULL, EPISODE_TYPE_TRAILER
from .podcast import Podcast
from .episode import Episode
from .media import Media
Expand Down
3 changes: 3 additions & 0 deletions podgen/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
EPISODE_TYPE_FULL = "full"
EPISODE_TYPE_TRAILER = "trailer"
EPISODE_TYPE_BONUS = "bonus"
37 changes: 37 additions & 0 deletions podgen/episode.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from podgen.warnings import NotSupportedByItunesWarning
from podgen.util import formatRFC2822, listToHumanreadableStr
from podgen.constants import EPISODE_TYPE_FULL, EPISODE_TYPE_TRAILER, EPISODE_TYPE_BONUS
from podgen.compat import string_types


Expand Down Expand Up @@ -174,6 +175,8 @@ def __init__(self, **kwargs):

self.__position = None

self.__episode_type = EPISODE_TYPE_FULL

self.subtitle = None
"""A short subtitle.
Expand Down Expand Up @@ -300,6 +303,13 @@ def rss_entry(self):
'{%s}isClosedCaptioned' % ITUNES_NS)
is_closed_captioned.text = 'Yes'

if self.__episode_type != EPISODE_TYPE_FULL:
episode_type = etree.SubElement(
entry,
'{%s}episodeType' % ITUNES_NS
)
episode_type.text = self.__episode_type

if self.__position is not None and self.__position >= 0:
order = etree.SubElement(entry, '{%s}order' % ITUNES_NS)
order.text = str(self.__position)
Expand Down Expand Up @@ -532,6 +542,33 @@ def explicit(self, explicit):
else:
self.__explicit = None

@property
def episode_type(self):
"""Indicate whether this is a full episode, or a bonus or trailer for
an episode or a season.
By default, the episode is taken to be a full episode.
Use the constants ``EPISODE_TYPE_FULL``, ``EPISODE_TYPE_TRAILER`` or
``EPISODE_TYPE_BONUS`` (available to import from ``podgen``).
:type: One of the three constants mentioned.
:RSS: itunes:episodeType
"""
return self.__episode_type

@episode_type.setter
def episode_type(self, episode_type):
as_str = str(episode_type)
if (as_str not in (
EPISODE_TYPE_FULL,
EPISODE_TYPE_BONUS,
EPISODE_TYPE_TRAILER,
)):
raise ValueError('Invalid episode_type value "%s"' % as_str)

self.__episode_type = as_str

@property
def position(self):
"""A custom position for this episode on the iTunes store page.
Expand Down
31 changes: 30 additions & 1 deletion podgen/tests/test_episode.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from lxml import etree

from podgen import Person, Media, Podcast, htmlencode, Episode, \
NotSupportedByItunesWarning
NotSupportedByItunesWarning, EPISODE_TYPE_FULL, EPISODE_TYPE_BONUS, \
EPISODE_TYPE_TRAILER
import datetime
import pytz
from dateutil.parser import parse as parsedate
Expand Down Expand Up @@ -512,6 +513,34 @@ def get_element():
assert get_element() is not None
self.assertEqual(get_element().text.lower(), "yes")

def test_episodeType(self):
def get_element():
return self.fe.rss_entry()\
.find("{%s}episodeType" % self.itunes_ns)

# Starts out as "full"
self.assertEqual(self.fe.episode_type, EPISODE_TYPE_FULL)

# Not used when set to "full"
assert get_element() is None

# Used when set to "trailer"
self.fe.episode_type = EPISODE_TYPE_TRAILER
assert get_element() is not None
self.assertEqual(get_element().text.lower(), "trailer")

# Used when set to "bonus"
self.fe.episode_type = EPISODE_TYPE_BONUS
assert get_element() is not None
self.assertEqual(get_element().text.lower(), "bonus")

# Fails when set to anything else
with self.assertRaises(ValueError):
self.fe.episode_type = "banana"

with self.assertRaises(ValueError):
self.fe.episode_type = False

def test_link(self):
def get_element():
return self.fe.rss_entry().find("link")
Expand Down

0 comments on commit 903a4bf

Please sign in to comment.