Private GIT

Skip to content
Snippets Groups Projects
Commit 2094f0d1 authored by miigotu's avatar miigotu
Browse files

Make sure subtitle last_search for an episode is convertible to datetime

parent bb244c55
Branches
Tags
No related merge requests found
...@@ -396,7 +396,7 @@ class SubtitlesFinder(object): ...@@ -396,7 +396,7 @@ class SubtitlesFinder(object):
logger.log(u"Starting post-process with default settings now that we found subtitles") logger.log(u"Starting post-process with default settings now that we found subtitles")
processTV.processDir(sickbeard.TV_DOWNLOAD_DIR) processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)
def run(self, force=False): # pylint: disable=unused-argument def run(self, force=False): # pylint: disable=unused-argument,too-many-statements,too-many-branches
if not sickbeard.USE_SUBTITLES: if not sickbeard.USE_SUBTITLES:
return return
...@@ -420,6 +420,13 @@ class SubtitlesFinder(object): ...@@ -420,6 +420,13 @@ class SubtitlesFinder(object):
# - search count < 2 and diff(airdate, now) > 1 week : now -> 1d # - search count < 2 and diff(airdate, now) > 1 week : now -> 1d
# - search count < 7 and diff(airdate, now) <= 1 week : now -> 4h -> 8h -> 16h -> 1d -> 1d -> 1d # - search count < 7 and diff(airdate, now) <= 1 week : now -> 4h -> 8h -> 16h -> 1d -> 1d -> 1d
"""
Defines the hours to wait between 2 subtitles search depending on:
- the episode: new or old
- the number of searches done so far (searchcount), represented by the index of the list
"""
rules = {'old': [0, 24], 'new': [0, 4, 8, 4, 16, 24, 24]}
today = datetime.date.today().toordinal() today = datetime.date.today().toordinal()
database = db.DBConnection() database = db.DBConnection()
...@@ -437,7 +444,6 @@ class SubtitlesFinder(object): ...@@ -437,7 +444,6 @@ class SubtitlesFinder(object):
self.amActive = False self.amActive = False
return return
rules = self._get_rules()
now = datetime.datetime.now() now = datetime.datetime.now()
for ep_to_sub in sql_results: for ep_to_sub in sql_results:
...@@ -453,12 +459,15 @@ class SubtitlesFinder(object): ...@@ -453,12 +459,15 @@ class SubtitlesFinder(object):
continue continue
try: try:
try:
lastsearched = datetime.datetime.strptime(ep_to_sub['lastsearch'], dateTimeFormat)
except ValueError:
lastsearched = datetime.datetime.min
if ((ep_to_sub['airdate_daydiff'] > 7 and ep_to_sub['searchcount'] < 2 and if ((ep_to_sub['airdate_daydiff'] > 7 and ep_to_sub['searchcount'] < 2 and
now - datetime.datetime.strptime(ep_to_sub['lastsearch'], dateTimeFormat) > now - lastsearched > datetime.timedelta(hours=rules['old'][ep_to_sub['searchcount']])) or
datetime.timedelta(hours=rules['old'][ep_to_sub['searchcount']])) or
(ep_to_sub['airdate_daydiff'] <= 7 and ep_to_sub['searchcount'] < 7 and (ep_to_sub['airdate_daydiff'] <= 7 and ep_to_sub['searchcount'] < 7 and
now - datetime.datetime.strptime(ep_to_sub['lastsearch'], dateTimeFormat) > now - lastsearched > datetime.timedelta(hours=rules['new'][ep_to_sub['searchcount']]))):
datetime.timedelta(hours=rules['new'][ep_to_sub['searchcount']]))):
logger.log(u'Downloading subtitles for %s S%02dE%02d' 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) % (ep_to_sub['show_name'], ep_to_sub['season'], ep_to_sub['episode']), logger.DEBUG)
...@@ -495,15 +504,6 @@ class SubtitlesFinder(object): ...@@ -495,15 +504,6 @@ class SubtitlesFinder(object):
self.amActive = False self.amActive = False
@staticmethod
def _get_rules():
"""
Define the hours to wait between 2 subtitles search depending on:
- the episode: new or old
- the number of searches done so far (searchcount), represented by the index of the list
"""
return {'old': [0, 24], 'new': [0, 4, 8, 4, 16, 24, 24]}
def run_subs_extra_scripts(episode_object, found_subtitles, video, single=False): def run_subs_extra_scripts(episode_object, found_subtitles, video, single=False):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment