From 5cd7ad2afb722a27b415c50ec04561ecbe003437 Mon Sep 17 00:00:00 2001 From: echel0n Date: Sun, 16 Mar 2014 06:33:00 -0700 Subject: [PATCH] Fixed issue that was causing malformed dates for shows, now SB will smartly set the date even if one didn't exist so that we don't just toss the episode away so long as we have enough data to satisfiy us. --- lib/tvrage_api/tvrage_api.py | 6 +++--- sickbeard/tv.py | 14 +++++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/tvrage_api/tvrage_api.py b/lib/tvrage_api/tvrage_api.py index 5405d5c0..3aab1e3b 100644 --- a/lib/tvrage_api/tvrage_api.py +++ b/lib/tvrage_api/tvrage_api.py @@ -398,13 +398,13 @@ class TVRage: elm.tag = robj.sub(lambda m: reDict[m.group(0)], elm.tag) if elm.tag in 'firstaired': - if elm.text is "0000-00-00": - elm.text = str(dt.date.fromordinal(1)) try: + elm.text = re.sub("(0{4})([-]0{2}){1,}", str(dt.date.fromordinal(1)), elm.text) + elm.text = re.sub("([-]0{2}){1,}", "", elm.text) fixDate = parse(elm.text, fuzzy=True).date() elm.text = fixDate.strftime("%Y-%m-%d") except: - pass + continue return ElementTree.fromstring(ElementTree.tostring(xml)) except SyntaxError: src = self._loadUrl(url, params) diff --git a/sickbeard/tv.py b/sickbeard/tv.py index 419791ad..409c9f5f 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -1348,13 +1348,10 @@ class TVEpisode(object): self.description = getattr(myEp, 'overview', "") try: - firstaired = "0000-00-00" - if getattr(myEp, 'firstaired', None) is not None: - firstaired = myEp['firstaired'] - - if firstaired is "0000-00-00": - firstaired = str(datetime.date.fromordinal(1)) + firstaired = getattr(myEp, 'firstaired', None) + if firstaired is None: raise ValueError + firstaired = re.sub("(0{4})([-]0{2}){1,}", str(datetime.date.fromordinal(1)), firstaired) rawAirdate = [int(x) for x in firstaired.split("-")] self.airdate = datetime.date(rawAirdate[0], rawAirdate[1], rawAirdate[2]) except ValueError: @@ -1365,9 +1362,8 @@ class TVEpisode(object): return False #early conversion to int so that episode doesn't get marked dirty - if getattr(myEp, 'id', None) is not None: - self.indexerid = int(myEp['id']) - else: + self.indexerid = getattr(myEp, 'id', None) + if self.indexerid is None: logger.log(u"Failed to retrieve ID from " + self.indexer, logger.ERROR) if self.indexerid != -1: self.deleteEpisode()