Skip to content

Commit

Permalink
Merge pull request midgetspy#565 from JackDandy/ChangeFileDate
Browse files Browse the repository at this point in the history
Add new feature, set file date to episode aired date.
  • Loading branch information
WebSpider committed May 14, 2014
2 parents d770722 + c33b928 commit 1ebe5a7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
12 changes: 12 additions & 0 deletions gui/slick/interfaces/default/config_postProcessing.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
5 changes: 4 additions & 1 deletion sickbeard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
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
Expand Down Expand Up @@ -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, \
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions sickbeard/postProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,9 @@ def process(self):
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)
Expand Down
41 changes: 41 additions & 0 deletions sickbeard/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,48 @@ def refreshDir(self):
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
Expand Down
3 changes: 2 additions & 1 deletion sickbeard/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ def savePostProcessing(self, naming_pattern=None, naming_multi_ep=None,
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,
Expand Down Expand Up @@ -1169,6 +1169,7 @@ def savePostProcessing(self, naming_pattern=None, naming_multi_ep=None,
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)
Expand Down

0 comments on commit 1ebe5a7

Please sign in to comment.