Format weeks as titles by default (for DVD sync)

This commit is contained in:
Etoh 2014-04-18 10:52:08 +01:00
parent 7769b7d936
commit d032a72869

View File

@ -64,7 +64,7 @@ def parseTime(timeStr):
time_params[name] = int(param) time_params[name] = int(param)
return datetime.timedelta(**time_params).total_seconds() return datetime.timedelta(**time_params).total_seconds()
def formatTime(timeInSeconds): def formatTime(timeInSeconds, weeksAsTitles=True):
if(timeInSeconds < 0): if(timeInSeconds < 0):
timeInSeconds = -timeInSeconds timeInSeconds = -timeInSeconds
sign = '-' sign = '-'
@ -72,18 +72,26 @@ def formatTime(timeInSeconds):
sign = '' sign = ''
timeInSeconds = round(timeInSeconds) timeInSeconds = round(timeInSeconds)
weeks = timeInSeconds // 604800 weeks = timeInSeconds // 604800
if weeksAsTitles and weeks > 0:
title = weeks
weeks = 0
else:
title = 0
days = (timeInSeconds % 604800) // 86400 days = (timeInSeconds % 604800) // 86400
hours = (timeInSeconds % 86400) // 3600 hours = (timeInSeconds % 86400) // 3600
minutes = (timeInSeconds % 3600) // 60 minutes = (timeInSeconds % 3600) // 60
seconds = timeInSeconds % 60 seconds = timeInSeconds % 60
if(weeks > 0): if(weeks > 0):
return '{0:}{1:.0f}w, {2:.0f}d, {3:02.0f}:{4:02.0f}:{5:02.0f}'.format(sign, weeks, days, hours, minutes, seconds) formattedTime = '{0:}{1:.0f}w, {2:.0f}d, {3:02.0f}:{4:02.0f}:{5:02.0f}'.format(sign, weeks, days, hours, minutes, seconds)
elif(days > 0): elif(days > 0):
return '{0:}{1:.0f}d, {2:02.0f}:{3:02.0f}:{4:02.0f}'.format(sign, days, hours, minutes, seconds) formattedTime = '{0:}{1:.0f}d, {2:02.0f}:{3:02.0f}:{4:02.0f}'.format(sign, days, hours, minutes, seconds)
elif(hours > 0): elif(hours > 0):
return '{0:}{1:02.0f}:{2:02.0f}:{3:02.0f}'.format(sign, hours, minutes, seconds) formattedTime = '{0:}{1:02.0f}:{2:02.0f}:{3:02.0f}'.format(sign, hours, minutes, seconds)
else: else:
return '{0:}{1:02.0f}:{2:02.0f}'.format(sign, minutes, seconds) formattedTime = '{0:}{1:02.0f}:{2:02.0f}'.format(sign, minutes, seconds)
if title > 0:
formattedTime = "{0:} (Title {1:.0f})".format(formattedTime, title)
return formattedTime
def findWorkingDir(): def findWorkingDir():
frozen = getattr(sys, 'frozen', '') frozen = getattr(sys, 'frozen', '')
@ -133,7 +141,7 @@ def blackholeStdoutForFrozenWindow():
# Relate to file hashing / difference checking: # Relate to file hashing / difference checking:
def stripfilename(filename): def stripfilename(filename):
return re.sub(constants.FILENAME_STRIP_REGEX,"",filename) return re.sub(constants.FILENAME_STRIP_REGEX, "", filename)
def hashFilename(filename): def hashFilename(filename):
return hashlib.sha256(stripfilename(filename).encode('utf-8')).hexdigest()[:12] return hashlib.sha256(stripfilename(filename).encode('utf-8')).hexdigest()[:12]