Use voussoirkit hms instead of local function.
This commit is contained in:
parent
9e322c18d4
commit
1a6abf00b9
2 changed files with 4 additions and 35 deletions
|
@ -13,6 +13,7 @@ import unicodedata
|
||||||
import zipstream
|
import zipstream
|
||||||
|
|
||||||
from voussoirkit import bytestring
|
from voussoirkit import bytestring
|
||||||
|
from voussoirkit import hms
|
||||||
from voussoirkit import imagetools
|
from voussoirkit import imagetools
|
||||||
from voussoirkit import pathclass
|
from voussoirkit import pathclass
|
||||||
|
|
||||||
|
@ -364,22 +365,6 @@ def hyphen_range(s):
|
||||||
|
|
||||||
return low, high
|
return low, high
|
||||||
|
|
||||||
def hms_to_seconds(hms):
|
|
||||||
'''
|
|
||||||
Convert hh:mm:ss string to an integer seconds.
|
|
||||||
'''
|
|
||||||
hms = hms.split(':')
|
|
||||||
seconds = 0
|
|
||||||
if len(hms) == 3:
|
|
||||||
seconds += int(hms[0]) * 3600
|
|
||||||
hms.pop(0)
|
|
||||||
if len(hms) == 2:
|
|
||||||
seconds += int(hms[0]) * 60
|
|
||||||
hms.pop(0)
|
|
||||||
if len(hms) == 1:
|
|
||||||
seconds += float(hms[0])
|
|
||||||
return seconds
|
|
||||||
|
|
||||||
def is_xor(*args):
|
def is_xor(*args):
|
||||||
'''
|
'''
|
||||||
Return True if and only if one arg is truthy.
|
Return True if and only if one arg is truthy.
|
||||||
|
@ -417,7 +402,7 @@ def parse_unit_string(s):
|
||||||
s = s.strip()
|
s = s.strip()
|
||||||
|
|
||||||
if ':' in s:
|
if ':' in s:
|
||||||
return hms_to_seconds(s)
|
return hms.hms_to_seconds(s)
|
||||||
|
|
||||||
elif all(c in '0123456789' for c in s):
|
elif all(c in '0123456789' for c in s):
|
||||||
return int(s)
|
return int(s)
|
||||||
|
@ -497,23 +482,6 @@ def run_generator(g):
|
||||||
for x in g:
|
for x in g:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def seconds_to_hms(seconds):
|
|
||||||
'''
|
|
||||||
Convert integer number of seconds to an hh:mm:ss string.
|
|
||||||
Only the necessary fields are used.
|
|
||||||
'''
|
|
||||||
seconds = math.ceil(seconds)
|
|
||||||
(minutes, seconds) = divmod(seconds, 60)
|
|
||||||
(hours, minutes) = divmod(minutes, 60)
|
|
||||||
parts = []
|
|
||||||
if hours:
|
|
||||||
parts.append(hours)
|
|
||||||
if hours or minutes:
|
|
||||||
parts.append(minutes)
|
|
||||||
parts.append(seconds)
|
|
||||||
hms = ':'.join(f'{part:02d}' for part in parts)
|
|
||||||
return hms
|
|
||||||
|
|
||||||
def slice_before(li, item):
|
def slice_before(li, item):
|
||||||
index = li.index(item)
|
index = li.index(item)
|
||||||
return li[:index]
|
return li[:index]
|
||||||
|
|
|
@ -10,6 +10,7 @@ import send2trash
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from voussoirkit import bytestring
|
from voussoirkit import bytestring
|
||||||
|
from voussoirkit import hms
|
||||||
from voussoirkit import pathclass
|
from voussoirkit import pathclass
|
||||||
from voussoirkit import sentinel
|
from voussoirkit import sentinel
|
||||||
from voussoirkit import spinal
|
from voussoirkit import spinal
|
||||||
|
@ -847,7 +848,7 @@ class Photo(ObjectBase):
|
||||||
def duration_string(self):
|
def duration_string(self):
|
||||||
if self.duration is None:
|
if self.duration is None:
|
||||||
return None
|
return None
|
||||||
return helpers.seconds_to_hms(self.duration)
|
return hms.seconds_to_hms(self.duration)
|
||||||
|
|
||||||
#@decorators.time_me
|
#@decorators.time_me
|
||||||
@decorators.required_feature('photo.generate_thumbnail')
|
@decorators.required_feature('photo.generate_thumbnail')
|
||||||
|
|
Loading…
Reference in a new issue