diff --git a/sickbeard/subtitles.py b/sickbeard/subtitles.py index d00255adcfbeee5d0b8ed18f18793618c6e3ad20..4a054bdcf206b53d71104b7694d23794bbdee4c7 100644 --- a/sickbeard/subtitles.py +++ b/sickbeard/subtitles.py @@ -439,6 +439,7 @@ class SubtitlesFinder(object): rules = self._get_rules() now = datetime.datetime.now() + for ep_to_sub in sql_results: if not ek(os.path.isfile, ep_to_sub['location']): @@ -451,44 +452,46 @@ class SubtitlesFinder(object): % (ep_to_sub['show_name'], ep_to_sub['season'], ep_to_sub['episode']), logger.DEBUG) continue - # http://bugs.python.org/issue7980#msg221094 - # I dont think this needs done here, but keeping to be safe (Recent shows rule) - datetime.datetime.strptime('20110101', '%Y%m%d') - if ((ep_to_sub['airdate_daydiff'] > 7 and ep_to_sub['searchcount'] < 2 and - now - datetime.datetime.strptime(ep_to_sub['lastsearch'], dateTimeFormat) > - datetime.timedelta(hours=rules['old'][ep_to_sub['searchcount']])) or - (ep_to_sub['airdate_daydiff'] <= 7 and ep_to_sub['searchcount'] < 7 and + try: + if ((ep_to_sub['airdate_daydiff'] > 7 and ep_to_sub['searchcount'] < 2 and now - datetime.datetime.strptime(ep_to_sub['lastsearch'], dateTimeFormat) > - datetime.timedelta(hours=rules['new'][ep_to_sub['searchcount']]))): - - logger.log(u'Downloading subtitles for %s S%02dE%02d' - % (ep_to_sub['show_name'], ep_to_sub['season'], ep_to_sub['episode']), logger.DEBUG) - - show_object = Show.find(sickbeard.showList, int(ep_to_sub['showid'])) - if not show_object: - logger.log(u'Show with ID %s not found in the database' % ep_to_sub['showid'], logger.DEBUG) - continue - - episode_object = show_object.getEpisode(int(ep_to_sub["season"]), int(ep_to_sub["episode"])) - if isinstance(episode_object, str): - logger.log(u'%s S%02dE%02d not found in the database' + datetime.timedelta(hours=rules['old'][ep_to_sub['searchcount']])) or + (ep_to_sub['airdate_daydiff'] <= 7 and ep_to_sub['searchcount'] < 7 and + now - datetime.datetime.strptime(ep_to_sub['lastsearch'], dateTimeFormat) > + datetime.timedelta(hours=rules['new'][ep_to_sub['searchcount']]))): + + logger.log(u'Downloading subtitles for %s S%02dE%02d' % (ep_to_sub['show_name'], ep_to_sub['season'], ep_to_sub['episode']), logger.DEBUG) - continue - - existing_subtitles = episode_object.subtitles - - try: - episode_object.download_subtitles() - except Exception as e: - logger.log(u'Unable to find subtitles for %s S%02dE%02d. Error: %r' - % (ep_to_sub['show_name'], ep_to_sub['season'], ep_to_sub['episode'], ex(e)), logger.ERROR) - continue - - new_subtitles = frozenset(episode_object.subtitles).difference(existing_subtitles) - if new_subtitles: - logger.log(u'Downloaded %s subtitles for %s S%02dE%02d' - % (', '.join(new_subtitles), ep_to_sub['show_name'], - ep_to_sub["season"], ep_to_sub["episode"])) + + show_object = Show.find(sickbeard.showList, int(ep_to_sub['showid'])) + if not show_object: + logger.log(u'Show with ID %s not found in the database' % ep_to_sub['showid'], logger.DEBUG) + continue + + episode_object = show_object.getEpisode(int(ep_to_sub["season"]), int(ep_to_sub["episode"])) + if isinstance(episode_object, str): + logger.log(u'%s S%02dE%02d not found in the database' + % (ep_to_sub['show_name'], ep_to_sub['season'], ep_to_sub['episode']), logger.DEBUG) + continue + + existing_subtitles = episode_object.subtitles + + try: + episode_object.download_subtitles() + except Exception as error: + logger.log(u'Unable to find subtitles for %s S%02dE%02d. Error: %r' + % (ep_to_sub['show_name'], ep_to_sub['season'], ep_to_sub['episode'], ex(error)), logger.ERROR) + continue + + new_subtitles = frozenset(episode_object.subtitles).difference(existing_subtitles) + if new_subtitles: + logger.log(u'Downloaded %s subtitles for %s S%02dE%02d' + % (', '.join(new_subtitles), ep_to_sub['show_name'], + ep_to_sub["season"], ep_to_sub["episode"])) + except Exception as error: + logger.log(u'Error while searching subtitles for %s S%02dE%02d. Error: %r' + % (ep_to_sub['show_name'], ep_to_sub['season'], ep_to_sub['episode'], ex(error)), logger.ERROR) + continue self.amActive = False