Change file modify date of episodes older than 1970 can be changed to airdate, log warning on set fail.

This commit is contained in:
Prinz23 2017-08-21 00:11:54 +01:00 committed by JackDandy
parent 35b282e797
commit a74f022ea3
3 changed files with 25 additions and 17 deletions

View file

@ -13,6 +13,7 @@
* Update Beautiful Soup 4.4.0 (r397) to 4.5.3 (r439)
* Update cachecontrol library 0.11.5 to 0.12.3 (db54c40)
* Update Certifi 2015.11.20.1 (385476b) to 2017.01.23 (9f9dc30)
* Update dateutil library 2.4.2 (d4baf97) to 2.6.1 (2f3a160)
* Update feedparser library 5.2.0 (8c62940) to 5.2.1 (f1dd1bb)
* Update html5lib 0.99999999/1.0b9 (46dae3d) to (1a28d72)
* Update IMDb 5.1dev20160106 to 5.1 (r907)
@ -79,6 +80,7 @@
* Change improve newnab autoselect categories
* Change add nzb.org BoxSD and BoxHD categories
* Change post processor, ignore symlinks found in process_dir
* Change file modify date of episodes older than 1970 can be changed to airdate, log warning on set fail
[develop changelog]

View file

@ -1017,15 +1017,14 @@ def set_up_anidb_connection():
return sickbeard.ADBA_CONNECTION.authed()
def touchFile(fname, atime=None):
if None != atime:
def touch_file(fname, atime=None):
if None is not atime:
try:
with open(fname, 'a'):
ek.ek(os.utime, fname, (atime, atime))
return True
except:
logger.log(u"File air date stamping not available on your OS", logger.DEBUG)
pass
return True
except (StandardError, Exception):
logger.log('File air date stamping not available on your OS', logger.DEBUG)
return False
@ -1581,3 +1580,13 @@ def is_link(filepath):
return invalid_file_attributes != attr and 0 != attr & file_attribute_reparse_point
return ek.ek(os.path.islink, filepath)
def datetime_to_epoch(dt):
""" convert a datetime to seconds after (or possibly before) 1970-1-1 """
""" can raise an error with dates pre 1970-1-1 """
if not isinstance(getattr(dt, 'tzinfo'), datetime.tzinfo):
from sickbeard.network_timezones import sb_timezone
dt = dt.replace(tzinfo=sb_timezone)
utc_naive = dt.replace(tzinfo=None) - dt.utcoffset()
return int((utc_naive - datetime.datetime(1970, 1, 1)).total_seconds())

View file

@ -2623,13 +2623,7 @@ class TVEpisode(object):
% (self.show.indexerid, ek.ek(os.path.basename, self.location)), logger.DEBUG)
return
hr = m = 0
airs = re.search('.*?(\d{1,2})(?::\s*?(\d{2}))?\s*(pm)?', self.show.airs, re.I)
if airs:
hr = int(airs.group(1))
hr = (12 + hr, hr)[None is airs.group(3)]
hr = (hr, hr - 12)[0 == hr % 12 and 0 != hr]
m = int((airs.group(2), m)[None is airs.group(2)])
hr, m = network_timezones.parse_time(self.show.airs)
airtime = datetime.time(hr, m)
airdatetime = datetime.datetime.combine(self.airdate, airtime)
@ -2637,12 +2631,15 @@ class TVEpisode(object):
filemtime = datetime.datetime.fromtimestamp(ek.ek(os.path.getmtime, self.location))
if filemtime != airdatetime:
import time
airdatetime = airdatetime.timetuple()
if helpers.touchFile(self.location, time.mktime(airdatetime)):
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), time.strftime('%b %d,%Y (%H:%M)', airdatetime)))
% (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)
def __getstate__(self):
d = dict(self.__dict__)