Skip to content

Commit

Permalink
Feature/ihracp 7252 (#20)
Browse files Browse the repository at this point in the history
* add tagerror

* IHRACP-5834: Pypodcaster repo gha production codeartifact (#17)

* deploy script update

* fixed tox configuration

* ci file added

* setting.init.example file

* Deploy to CodeArtifact ci added

* Deploy to CodeArtifact ci added

* Deploy to CodeArtifact ci added

* Delete .python-version

* upadte version file

* prod version codeartifact

---------

Co-authored-by: Patrick Daley <[email protected]>
Co-authored-by: Poonam Shinde <[email protected]>

* merge

* Revert "merge"

This reverts commit 2c85209e16167e915772aef0eb7eaeb1719e27a8.

* Revert "add tagerror"

This reverts commit 4c5982b87c9f82df7161dade0233d39ddfdd33ee.

* tag methods raise detailed invalidPodcastFeed errors

* individual error file

* logging fixes

* tox

* versions

* unit tests

---------

Co-authored-by: Ian Noyes <ian.noyes@iheartmedia_com>
Co-authored-by: poonamshinde-ihm <[email protected]>
Co-authored-by: Patrick Daley <[email protected]>
Co-authored-by: Poonam Shinde <[email protected]>
  • Loading branch information
5 people authored Aug 23, 2024
1 parent 0c1899b commit 0bd1c71
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 5 deletions.
2 changes: 2 additions & 0 deletions pypodcastparser/Error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class InvalidPodcastFeed(ValueError):
pass
41 changes: 41 additions & 0 deletions pypodcastparser/Item.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import pytz
import logging

from pypodcastparser.Error import InvalidPodcastFeed


LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -155,6 +158,8 @@ def set_time_published(self):
self.time_published = email.utils.mktime_tz(time_tuple)
except (TypeError, ValueError, IndexError):
self.time_published = None
except Exception:
raise InvalidPodcastFeed(f"Invalid Podcast Feed, episode level pubDate: {self.published_date_string}, could not be parsed")

def set_dates_published(self):
if self.time_published is None:
Expand All @@ -164,6 +169,8 @@ def set_dates_published(self):
self.date_time = datetime.date.fromtimestamp(self.time_published)
except ValueError:
self.date_time = None
except Exception:
raise InvalidPodcastFeed(f"Invalid Podcast Feed, episode level pubDate: {self.published_date_string}, could not be parsed")

def to_dict(self):
item = {}
Expand Down Expand Up @@ -195,13 +202,17 @@ def set_author(self, tag):
self.author = tag.string
except AttributeError:
self.author = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, episode level author could not be parsed")

def set_description(self, tag):
"""Parses description and set value."""
try:
self.description = tag.string
except AttributeError:
self.description = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, episode level description could not be parsed")

def set_content_encoded(self, tag):
"""Parses content_encoded and set value."""
Expand All @@ -211,6 +222,8 @@ def set_content_encoded(self, tag):
self.description = self.content_encoded
except AttributeError:
self.content_encoded = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, episode level content_encoded could not be parsed")

def set_enclosure(self, tag):
"""Parses enclosure_url, enclosure_type then set values."""
Expand All @@ -234,6 +247,8 @@ def set_guid(self, tag):
self.guid = tag.string
except AttributeError:
self.guid = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, episode level guid could not be parsed")

# TODO convert to one timezone
def set_published_date(self, tag):
Expand Down Expand Up @@ -344,13 +359,17 @@ def set_title(self, tag):
self.title = tag.string
except AttributeError:
self.title = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, episode level title could not be parsed")

def set_itunes_author_name(self, tag):
"""Parses author name from itunes tags and sets value"""
try:
self.itunes_author_name = tag.string
except AttributeError:
self.itunes_author_name = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, episode level itunes:author could not be parsed")

def set_itunes_episode(self, tag):
"""Parses the episode number and sets value"""
Expand All @@ -361,6 +380,8 @@ def set_itunes_episode(self, tag):
self.itunes_episode = "0"
except AttributeError:
self.itunes_episode = "0"
except Exception:
raise InvalidPodcastFeed(f"Invalid Podcast Feed, episode level itunes:episode: {tag.string}, could not be parsed")

def set_podcast_transcript(self, tag):
"""Parses the episode transcript and sets value
Expand All @@ -377,6 +398,8 @@ def set_podcast_transcript(self, tag):
self.podcast_transcript = self.transcriptionList
except AttributeError:
self.podcast_transcript = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, episode transcription could not be parsed")

def set_itunes_season(self, tag):
"""Parses the episode season and sets value"""
Expand All @@ -394,13 +417,17 @@ def set_itunes_episode_type(self, tag):
self.itunes_episode_type = self.itunes_episode_type.lower()
except AttributeError:
self.itunes_episode_type = None
except Exception:
raise InvalidPodcastFeed(f"Invalid Podcast Feed, episode level itunes:episodeType: {tag.string}, could not be parsed")

def set_itunes_block(self, tag):
"""Check and see if item is blocked from iTunes and sets value"""
try:
block = tag.string.lower()
except AttributeError:
block = ""
except Exception:
raise InvalidPodcastFeed(f"Invalid Podcast Feed, episode level itunes:block: {tag.string}, could not be parsed")
if block == "yes":
self.itunes_block = True
else:
Expand Down Expand Up @@ -436,6 +463,8 @@ def set_itunes_duration(self, tag):

except AttributeError:
self.itunes_duration = None
except Exception:
raise InvalidPodcastFeed(f"Invalid Podcast Feed, episode level itunes:duration: {tag.string}, could not be parsed")

def set_itunes_explicit(self, tag):
"""Parses explicit from itunes item tags and sets value"""
Expand All @@ -458,13 +487,17 @@ def set_itunes_explicit(self, tag):

except AttributeError:
self.itunes_explicit = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, episode level itunes:explicit could not be parsed")

def set_itunes_image(self, tag):
"""Parses itunes item images and set url as value"""
try:
self.itunes_image = tag.get("href")
except AttributeError:
self.itunes_image = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, episode level itunes:image could not be parsed")

def set_itunes_order(self, tag):
"""Parses episode order and set url as value"""
Expand All @@ -473,20 +506,26 @@ def set_itunes_order(self, tag):
self.itunes_order = self.itunes_order.lower()
except AttributeError:
self.itunes_order = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, episode level itunes:order could not be parsed")

def set_itunes_subtitle(self, tag):
"""Parses subtitle from itunes tags and sets value"""
try:
self.itunes_subtitle = tag.string
except AttributeError:
self.itunes_subtitle = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, episode level itunes:subtitle could not be parsed")

def set_itunes_summary(self, tag):
"""Parses summary from itunes tags and sets value"""
try:
self.itunes_summary = tag.string
except AttributeError:
self.itunes_summary = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, episode level itunes:summary could not be parsed")

def set_interactive(self, tag):
"""Parses author and set value."""
Expand All @@ -496,3 +535,5 @@ def set_interactive(self, tag):
except AttributeError:
self.interactive = False
self.is_interactive = self.interactive
except Exception:
raise InvalidPodcastFeed(f"Invalid Podcast Feed, episode level ihr:interactive: {tag.string}, could not be parsed")
47 changes: 43 additions & 4 deletions pypodcastparser/Podcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import datetime
import email.utils
from pypodcastparser.Item import Item


class InvalidPodcastFeed(ValueError):
pass
from pypodcastparser.Error import InvalidPodcastFeed


class Podcast:
Expand Down Expand Up @@ -160,6 +157,8 @@ def set_time_published(self):
self.time_published = email.utils.mktime_tz(time_tuple)
except (TypeError, ValueError, IndexError):
self.time_published = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level pubDate could not be parsed")

def set_dates_published(self):
if self.time_published is None:
Expand All @@ -169,6 +168,8 @@ def set_dates_published(self):
self.date_time = datetime.date.fromtimestamp(self.time_published)
except ValueError:
self.date_time = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level pubDate could not be parsed")

def to_dict(self):
"""Create dict representation of Podcast object."""
Expand Down Expand Up @@ -222,27 +223,35 @@ def set_copyright(self, tag):
self.copyright = tag.string
except AttributeError:
self.copyright = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level copyright could not be parsed")

def set_description(self, tag):
"""Parses description and sets value"""
try:
self.description = tag.string
except AttributeError:
self.description = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level description could not be parsed")

def set_image(self, tag):
"""Parses image element and set values"""
try:
self.image_url = tag.find("url", recursive=False).string
except AttributeError:
self.image_url = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level image could not be parsed")

def set_itunes_author_name(self, tag):
"""Parses author name from itunes tags and sets value"""
try:
self.itunes_author_name = tag.string
except AttributeError:
self.itunes_author_name = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level itunes:author could not be parsed")

def set_itunes_type(self, tag):
"""Parses the type of show and sets value"""
Expand All @@ -251,13 +260,17 @@ def set_itunes_type(self, tag):
self.itunes_type = self.itunes_type.lower()
except AttributeError:
self.itunes_type = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level itunes:type could not be parsed")

def set_itunes_block(self, tag):
"""Check and see if podcast is blocked from iTunes and sets value"""
try:
block = tag.string.lower()
except AttributeError:
block = ""
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level itunes:block could not be parsed")
if block == "yes":
self.itunes_block = True
else:
Expand Down Expand Up @@ -286,20 +299,26 @@ def set_itunes_complete(self, tag):
self.itunes_complete = tag.string.lower()
except AttributeError:
self.itunes_complete = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level itunes:complete could not be parsed")

def set_itunes_explicit(self, tag):
"""Parses explicit from itunes tags and sets value"""
try:
self.itunes_explicit = tag.string.lower()
except AttributeError:
self.itunes_explicit = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level itunes:explicit could not be parsed")

def set_itunes_image(self, tag):
"""Parses itunes images and set url as value"""
try:
self.itunes_image = tag.get("href")
except AttributeError:
self.itunes_image = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level itunes:image could not be parsed")

def set_itunes_keywords(self, tag):
"""Parses and adds itunes keywords"""
Expand All @@ -319,20 +338,26 @@ def set_itunes_keywords(self, tag):
self.itunes_keywords = unique_keywords_list
except AttributeError:
self.itunes_keywords = []
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level itunes:keywords could not be parsed")

def set_itunes_new_feed_url(self, tag):
"""Parses new feed url from itunes tags and sets value"""
try:
self.itunes_new_feed_url = tag.string
except AttributeError:
self.itunes_new_feed_url = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level itunes:new-feed-url could not be parsed")

def set_language(self, tag):
"""Parses feed language and set value"""
try:
self.language = tag.string
except AttributeError:
self.language = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level language could not be parsed")

def set_last_build_date(self, tag):
"""Parses last build date and set value"""
Expand All @@ -347,6 +372,8 @@ def set_link(self, tag):
self.link = tag.string
except AttributeError:
self.link = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level link could not be parsed")

def set_published_date(self, tag):
"""Parses published date and set value"""
Expand All @@ -364,6 +391,8 @@ def set_published_date(self, tag):
)
except AttributeError:
self.published_date = None
except Exception:
raise InvalidPodcastFeed(f"Invalid Podcast Feed, show level pubDate: {tag.string}, could not be parsed")

def set_owner(self, tag):
"""Parses owner name and email then sets value"""
Expand All @@ -375,27 +404,35 @@ def set_owner(self, tag):
self.owner_email = tag.find("itunes:email", recursive=False).string
except AttributeError:
self.owner_email = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level itunes:owner could not be parsed")

def set_subtitle(self, tag):
"""Parses subtitle and sets value"""
try:
self.subtitle = tag.string
except AttributeError:
self.subtitle = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level subtitle could not be parsed")

def set_summary(self, tag):
"""Parses summary and set value"""
try:
self.summary = tag.string
except AttributeError:
self.summary = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level summary could not be parsed")

def set_title(self, tag):
"""Parses title and set value"""
try:
self.title = tag.string
except AttributeError:
self.title = None
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level title could not be parsed")

def set_interactive(self, tag):
"""Parses ihr-interactive and set value"""
Expand All @@ -405,3 +442,5 @@ def set_interactive(self, tag):
except AttributeError:
self.interactive = False
self.is_interactive = self.interactive
except Exception:
raise InvalidPodcastFeed("Invalid Podcast Feed, show level ihr:interactive could not be parsed")
1 change: 1 addition & 0 deletions requirements-ci.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
twine==4.0.2
importlib-metadata==6.8.0
wheel==0.42.0
Loading

0 comments on commit 0bd1c71

Please sign in to comment.