1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-12 11:02:21 -05:00

Merge pull request #565 from JackDandy/ChangeFileDate

Add new feature, set file date to episode aired date.
This commit is contained in:
Nils 2014-05-14 17:03:54 +02:00
commit 1ebe5a7c3c
5 changed files with 62 additions and 2 deletions

View File

@ -118,6 +118,18 @@
</label>
</div>
<div class="field-pair">
<input type="checkbox" name="airdate_episodes" id="airdate_episodes" #if $sickbeard.AIRDATE_EPISODES == True then "checked=\"checked\"" else ""# />
<label class="clearfix" for="airdate_episodes">
<span class="component-title">Change File Date</span>
<span class="component-desc">Set last modified filedate to the date that the episode aired?</span>
</label>
<label class="nocheck clearfix">
<span class="component-title">&nbsp;</span>
<span class="component-desc"><b>NOTE:</b> Some systems may ignore this feature.</span>
</label>
</div>
<div class="field-pair">
<input type="checkbox" name="process_automatically" id="process_automatically" #if $sickbeard.PROCESS_AUTOMATICALLY == True then "checked=\"checked\"" else ""# />
<label class="clearfix" for="process_automatically">

View File

@ -267,6 +267,7 @@ SPEEDCD_FREELEECH = None
ADD_SHOWS_WO_DIR = None
CREATE_MISSING_SHOW_DIRS = None
RENAME_EPISODES = False
AIRDATE_EPISODES = False
PROCESS_AUTOMATICALLY = False
KEEP_PROCESSED_DIR = False
PROCESS_METHOD = None
@ -514,7 +515,7 @@ def initialize(consoleLogging=True):
KEEP_PROCESSED_DIR, PROCESS_METHOD, TV_DOWNLOAD_DIR, MIN_SEARCH_FREQUENCY, DEFAULT_UPDATE_FREQUENCY, MIN_UPDATE_FREQUENCY, UPDATE_FREQUENCY, \
showQueueScheduler, searchQueueScheduler, ROOT_DIRS, CACHE_DIR, ACTUAL_CACHE_DIR, \
NAMING_PATTERN, NAMING_MULTI_EP, NAMING_FORCE_FOLDERS, NAMING_ABD_PATTERN, NAMING_CUSTOM_ABD, NAMING_SPORTS_PATTERN, NAMING_CUSTOM_SPORTS, NAMING_STRIP_YEAR, \
RENAME_EPISODES, properFinderScheduler, PROVIDER_ORDER, autoPostProcesserScheduler, \
RENAME_EPISODES, AIRDATE_EPISODES, properFinderScheduler, PROVIDER_ORDER, autoPostProcesserScheduler, \
WOMBLE, OMGWTFNZBS, OMGWTFNZBS_USERNAME, OMGWTFNZBS_APIKEY, providerList, newznabProviderList, torrentRssProviderList, \
EXTRA_SCRIPTS, USE_TWITTER, TWITTER_USERNAME, TWITTER_PASSWORD, TWITTER_PREFIX, \
USE_BOXCAR, BOXCAR_USERNAME, BOXCAR_PASSWORD, BOXCAR_NOTIFY_ONDOWNLOAD, BOXCAR_NOTIFY_ONSUBTITLEDOWNLOAD, BOXCAR_NOTIFY_ONSNATCH, \
@ -690,6 +691,7 @@ def initialize(consoleLogging=True):
PROCESS_AUTOMATICALLY = check_setting_int(CFG, 'General', 'process_automatically', 0)
UNPACK = check_setting_int(CFG, 'General', 'unpack', 0)
RENAME_EPISODES = check_setting_int(CFG, 'General', 'rename_episodes', 1)
AIRDATE_EPISODES = check_setting_int(CFG, 'General', 'airdate_episodes', 0)
KEEP_PROCESSED_DIR = check_setting_int(CFG, 'General', 'keep_processed_dir', 1)
PROCESS_METHOD = check_setting_str(CFG, 'General', 'process_method', 'copy' if KEEP_PROCESSED_DIR else 'move')
MOVE_ASSOCIATED_FILES = check_setting_int(CFG, 'General', 'move_associated_files', 0)
@ -1448,6 +1450,7 @@ def save_config():
new_config['General']['process_automatically'] = int(PROCESS_AUTOMATICALLY)
new_config['General']['unpack'] = int(UNPACK)
new_config['General']['rename_episodes'] = int(RENAME_EPISODES)
new_config['General']['airdate_episodes'] = int(AIRDATE_EPISODES)
new_config['General']['create_missing_show_dirs'] = int(CREATE_MISSING_SHOW_DIRS)
new_config['General']['add_shows_wo_dir'] = int(ADD_SHOWS_WO_DIR)

View File

@ -973,6 +973,9 @@ class PostProcessor(object):
with cur_ep.lock:
cur_ep.location = ek.ek(os.path.join, dest_path, new_file_name)
cur_ep.saveToDB()
# set file modify stamp to show airdate
if sickbeard.AIRDATE_EPISODES:
ep_obj.show.airdateModifyStamp(cur_ep)
# log it to history
history.logDownload(ep_obj, self.file_path, new_ep_quality, self.release_group)

View File

@ -966,7 +966,48 @@ class TVShow(object):
curEp.hastbn = False
curEp.release_name = ''
curEp.saveToDB()
else:
# the file exists, set its modify file stamp
if sickbeard.AIRDATE_EPISODES:
self.airdateModifyStamp(curEp)
def airdateModifyStamp(self, ep_obj):
"""
Make the modify date and time of a file reflect the show air date and time.
Note: Also called from postProcessor
"""
hr = min = 0
airs = re.search('.*?(\d{1,2})(?::\s*?(\d{2}))?\s*(pm)?', ep_obj.show.airs, re.I)
if airs:
hr = int(airs.group(1))
hr = (12 + hr, hr)[None is airs.group(3)]
min = int((airs.group(2), min)[None is airs.group(2)])
airtime = datetime.time(hr, min)
airdatetime = datetime.datetime.combine(ep_obj.airdate, airtime)
filemtime = datetime.datetime.fromtimestamp(os.path.getmtime(ep_obj.location))
if filemtime != airdatetime:
import time
airdatetime = airdatetime.timetuple()
if self.touch(ep_obj.location, time.mktime(airdatetime)):
logger.log(str(self.indexerid) + u": Changed modify date of " + os.path.basename(ep_obj.location)
+ " to show air date " + time.strftime("%b %d,%Y (%H:%M)", airdatetime))
def touch(self, fname, atime = None):
if None != atime:
try:
with file(fname, 'a'):
os.utime(fname, (atime, atime))
return True
except:
logger.log(u"File air date stamping not available on your OS", logger.DEBUG)
pass
return False
def downloadSubtitles(self, force=False):
#TODO: Add support for force option

View File

@ -1138,7 +1138,7 @@ class ConfigPostProcessing:
xbmc_data=None, xbmc_12plus_data=None, mediabrowser_data=None, sony_ps3_data=None,
wdtv_data=None, tivo_data=None, mede8er_data=None,
keep_processed_dir=None, process_method=None, process_automatically=None,
rename_episodes=None, unpack=None,
rename_episodes=None, airdate_episodes=None, unpack=None,
move_associated_files=None, tv_download_dir=None, naming_custom_abd=None,
naming_abd_pattern=None, naming_strip_year=None, use_failed_downloads=None,
delete_failed=None, extra_scripts=None,
@ -1169,6 +1169,7 @@ class ConfigPostProcessing:
sickbeard.PROCESS_METHOD = process_method
sickbeard.EXTRA_SCRIPTS = [x.strip() for x in extra_scripts.split('|') if x.strip()]
sickbeard.RENAME_EPISODES = config.checkbox_to_value(rename_episodes)
sickbeard.AIRDATE_EPISODES = config.checkbox_to_value(airdate_episodes)
sickbeard.MOVE_ASSOCIATED_FILES = config.checkbox_to_value(move_associated_files)
sickbeard.NAMING_CUSTOM_ABD = config.checkbox_to_value(naming_custom_abd)
sickbeard.NAMING_CUSTOM_SPORTS = config.checkbox_to_value(naming_custom_sports)