update Shared
This commit is contained in:
parent
e7ebbedd38
commit
6881f3471a
184 changed files with 13080 additions and 13691 deletions
|
|
@ -30,6 +30,8 @@ def toAZ(num):
|
|||
az = digits[r] + az
|
||||
return az
|
||||
|
||||
encode_base26=toAZ
|
||||
|
||||
def fromAZ(num):
|
||||
"""
|
||||
Converts a bijective base 26 string to an integer
|
||||
|
|
@ -71,6 +73,8 @@ def to26(q):
|
|||
converted.insert(0, l)
|
||||
return "".join(converted) or 'A'
|
||||
|
||||
decode_base26=toAZ
|
||||
|
||||
def from26(q):
|
||||
"""
|
||||
Converts an base 26 string to an integer
|
||||
|
|
@ -402,6 +406,37 @@ def format_duration(ms, verbosity=0, years=True, hours=True, milliseconds=True):
|
|||
duration = ' '.join(durations)
|
||||
return duration
|
||||
|
||||
def format_timecode(seconds):
|
||||
'''
|
||||
>>> format_timecode(3599.999)
|
||||
'00:59:59.999'
|
||||
'''
|
||||
seconds = float(seconds)
|
||||
d = int(seconds / 86400)
|
||||
h = int(seconds % 86400 / 3600)
|
||||
m = int(seconds % 3600 / 60)
|
||||
s = float(seconds % 60)
|
||||
duration = "%s%02d:%02d:%06.3f" % ('%d:' % d if d else '', h, m, s)
|
||||
return duration
|
||||
|
||||
def parse_timecode(string):
|
||||
'''
|
||||
Takes a formatted timecode, returns seconds
|
||||
|
||||
>> parse_timecode('1:02:03:04.05')
|
||||
93784.05
|
||||
>> parse_timecode('3')
|
||||
3.0
|
||||
>> parse_timecode('2:')
|
||||
120
|
||||
>> parse_timecode('1::')
|
||||
3600.0
|
||||
'''
|
||||
timecode = 0
|
||||
for i, v in enumerate(list(reversed(string.split(':')))[:4]):
|
||||
timecode += float(v) * ( 86400 if i == 3 else pow(60, i))
|
||||
return timecode
|
||||
|
||||
def ms2runtime(ms, shortenLong=False):
|
||||
# deprecated - use format_duration
|
||||
'''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue