From f97dac58b7d99aae1cdacf84f1e7b1e50a1116a8 Mon Sep 17 00:00:00 2001 From: JackDandy Date: Mon, 21 Aug 2017 14:27:22 +0100 Subject: [PATCH] Change episodes older than 1970 may already exist. Change compare file mtime as int to epoch. Change handle datetime_to_epoch error. --- sickbeard/tv.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/sickbeard/tv.py b/sickbeard/tv.py index 07653b6f..4638d7cf 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -2626,20 +2626,22 @@ class TVEpisode(object): hr, m = network_timezones.parse_time(self.show.airs) airtime = datetime.time(hr, m) - airdatetime = datetime.datetime.combine(self.airdate, airtime) + aired_dt = datetime.datetime.combine(self.airdate, airtime) + try: + aired_epoch = helpers.datetime_to_epoch(aired_dt) + filemtime = int(ek.ek(os.path.getmtime, self.location)) + except (StandardError, Exception): + return - filemtime = datetime.datetime.fromtimestamp(ek.ek(os.path.getmtime, self.location)) + if filemtime != aired_epoch: - if filemtime != airdatetime: + result, loglevel = 'Changed', logger.MESSAGE + if not helpers.touch_file(self.location, aired_epoch): + result, loglevel = 'Error changing', logger.WARNING - if helpers.touch_file(self.location, helpers.datetime_to_epoch(airdatetime)): - logger.log('%s: Changed modify date of %s to show air date %s' - % (self.show.indexerid, ek.ek(os.path.basename, self.location), - airdatetime.strftime('%b %d,%Y (%H:%M)'))) - else: - logger.log('%s: Error changing modify date of %s to show air date %s, Error: %s' - % (self.show.indexerid, ek.ek(os.path.basename, self.location), - airdatetime.strftime('%b %d,%Y (%H:%M)'), e.message), logger.WARNING) + logger.log('%s: %s modify date of %s to show air date %s' + % (self.show.indexerid, result, ek.ek(os.path.basename, self.location), + aired_dt.strftime('%b %d,%Y (%H:%M)')), loglevel) def __getstate__(self): d = dict(self.__dict__)