update utils
This commit is contained in:
parent
bb9f8fc445
commit
791fbbc3c7
1 changed files with 33 additions and 0 deletions
33
utils.py
33
utils.py
|
|
@ -1,4 +1,16 @@
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
|
def resolve_roman(s):
|
||||||
|
extra = re.compile(r'^\d+(.*?)$').findall(s)
|
||||||
|
if extra:
|
||||||
|
extra = extra[0].lower()
|
||||||
|
new = {
|
||||||
|
'i': '1', 'ii': '2', 'iii': '3', 'iv': '4', 'v': '5',
|
||||||
|
'vi': '6', 'vii': 7, 'viii': '8', 'ix': '9', 'x': '10'
|
||||||
|
}.get(extra, extra)
|
||||||
|
return s.replace(extra, new)
|
||||||
|
return s
|
||||||
|
|
||||||
def upgrade_originals():
|
def upgrade_originals():
|
||||||
import item.models
|
import item.models
|
||||||
|
|
@ -30,3 +42,24 @@ def remove_deselected_files():
|
||||||
if changed:
|
if changed:
|
||||||
i.save()
|
i.save()
|
||||||
|
|
||||||
|
def write_if_new(path, data, mode=''):
|
||||||
|
read_mode = 'r' + mode
|
||||||
|
write_mode = 'w' + mode
|
||||||
|
if os.path.exists(path):
|
||||||
|
with open(path, read_mode) as fd:
|
||||||
|
old = fd.read()
|
||||||
|
else:
|
||||||
|
old = ""
|
||||||
|
is_new = data != old
|
||||||
|
if path.endswith(".kdenlive"):
|
||||||
|
is_new = re.sub(r'\{.{36}\}', '', data) != re.sub(r'\{.{36}\}', '', old)
|
||||||
|
if is_new:
|
||||||
|
with open(path, write_mode) as fd:
|
||||||
|
fd.write(data)
|
||||||
|
|
||||||
|
def format_duration(duration, fps, audio=False):
|
||||||
|
if audio:
|
||||||
|
return float('%0.5f' % (int(duration * fps) / fps))
|
||||||
|
else:
|
||||||
|
return float('%0.5f' % (round(duration * fps) / fps))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue