CC-5276: Adding watched folder throws exception sometimes
Fixed by only converting length format if it is not already in the correct format
This commit is contained in:
parent
8ba95b3587
commit
6501d563be
1 changed files with 22 additions and 14 deletions
|
@ -474,20 +474,28 @@ def truncate_to_value(item, value):
|
||||||
return str(item)
|
return str(item)
|
||||||
|
|
||||||
def format_length(mutagen_length):
|
def format_length(mutagen_length):
|
||||||
""" Convert mutagen length to airtime length """
|
if convert_format(mutagen_length):
|
||||||
t = float(mutagen_length)
|
""" Convert mutagen length to airtime length """
|
||||||
h = int(math.floor(t / 3600))
|
t = float(mutagen_length)
|
||||||
t = t % 3600
|
h = int(math.floor(t / 3600))
|
||||||
m = int(math.floor(t / 60))
|
t = t % 3600
|
||||||
s = t % 60
|
m = int(math.floor(t / 60))
|
||||||
# will be ss.uuu
|
s = t % 60
|
||||||
s = str('{0:f}'.format(s))
|
# will be ss.uuu
|
||||||
seconds = s.split(".")
|
s = str('{0:f}'.format(s))
|
||||||
s = seconds[0]
|
seconds = s.split(".")
|
||||||
# have a maximum of 6 subseconds.
|
s = seconds[0]
|
||||||
if len(seconds[1]) >= 6: ss = seconds[1][0:6]
|
# have a maximum of 6 subseconds.
|
||||||
else: ss = seconds[1][0:]
|
if len(seconds[1]) >= 6: ss = seconds[1][0:6]
|
||||||
return "%s:%s:%s.%s" % (h, m, s, ss)
|
else: ss = seconds[1][0:]
|
||||||
|
return "%s:%s:%s.%s" % (h, m, s, ss)
|
||||||
|
|
||||||
|
def convert_format(value):
|
||||||
|
regCompiled = re.compile("^[0-9][0-9]:[0-9][0-9]:[0-9][0-9](\.\d+)?$")
|
||||||
|
if re.search(regCompiled, str(value)) is None:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import doctest
|
import doctest
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue