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

@ -63,8 +63,8 @@ def parseTime(timeStr):
else: else:
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,19 +72,27 @@ 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', '')
if not frozen: if not frozen:
@ -120,7 +128,7 @@ def blackholeStdoutForFrozenWindow():
self._file.flush() self._file.flush()
sys.stderr = Stderr() sys.stderr = Stderr()
del Stderr del Stderr
class Blackhole(object): class Blackhole(object):
softspace = 0 softspace = 0
def write(self, text): def write(self, text):
@ -133,24 +141,24 @@ 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]
def hashFilesize(size): def hashFilesize(size):
return hashlib.sha256(str(size)).hexdigest()[:12] return hashlib.sha256(str(size)).hexdigest()[:12]
def sameHashed(string1raw, string1hashed, string2raw, string2hashed): def sameHashed(string1raw, string1hashed, string2raw, string2hashed):
if string1raw == string2raw: if string1raw == string2raw:
return True return True
elif string1raw == string2hashed: elif string1raw == string2hashed:
return True return True
elif string1hashed == string2raw: elif string1hashed == string2raw:
return True return True
elif string1hashed == string2hashed: elif string1hashed == string2hashed:
return True return True
def sameFilename (filename1, filename2): def sameFilename (filename1, filename2):
if filename1 == constants.PRIVACY_HIDDENFILENAME or filename2 == constants.PRIVACY_HIDDENFILENAME: if filename1 == constants.PRIVACY_HIDDENFILENAME or filename2 == constants.PRIVACY_HIDDENFILENAME:
return True return True
@ -166,7 +174,7 @@ def sameFilesize (filesize1, filesize2):
return True return True
else: else:
return False return False
def sameFileduration (duration1, duration2): def sameFileduration (duration1, duration2):
if abs(round(duration1) - round(duration2)) < constants.DIFFFERENT_DURATION_THRESHOLD: if abs(round(duration1) - round(duration2)) < constants.DIFFFERENT_DURATION_THRESHOLD:
return True return True