fixed progressbar crashing on non-video media
This commit is contained in:
parent
2929725416
commit
e94c3d166f
3 changed files with 29 additions and 11 deletions
18
aux.py
18
aux.py
|
@ -4,6 +4,7 @@
|
|||
import os
|
||||
import pathlib
|
||||
import over
|
||||
import re
|
||||
|
||||
# --------------------------------------------------
|
||||
|
||||
|
@ -17,6 +18,23 @@ def parse_fps(raw):
|
|||
|
||||
# --------------------------------------------------
|
||||
|
||||
def parse_time(raw):
|
||||
"""
|
||||
Parses ffmpeg's state sentence containing the time= token.
|
||||
|
||||
E.g. b"... time=00:01:11.85 ..."
|
||||
|
||||
Returns the time in seconds, e.g. 71.85.
|
||||
"""
|
||||
|
||||
s = re.findall(b"time=([^ ]+) ", raw)[0]
|
||||
|
||||
hh, mm, ss = (float(t) for t in s.split(b":"))
|
||||
|
||||
return hh * 3600 + mm * 60 + ss
|
||||
|
||||
# --------------------------------------------------
|
||||
|
||||
def to_Path(raw_path):
|
||||
"""
|
||||
Returns pathlib.Path pointing to raw_path, handling "~/" correctly.
|
||||
|
|
|
@ -262,9 +262,9 @@ if __name__ == "__main__":
|
|||
if out:
|
||||
output_buffer.append(out)
|
||||
|
||||
if b"frame=" in out:
|
||||
frame_id = re.findall(b"frame= *(\d+) ", out)[0]
|
||||
pb.set("a", int(frame_id) / info.video_fps.value)
|
||||
if b"time=" in out:
|
||||
t = aux.parse_time(out)
|
||||
pb.set("a", t)
|
||||
pb.render()
|
||||
|
||||
elif out is None:
|
||||
|
@ -398,11 +398,11 @@ if __name__ == "__main__":
|
|||
|
||||
if main.cfg.armed:
|
||||
pb = over.text.ProgressBar(
|
||||
"§%f §rs [§=f>§ F] §sf (§ss) (Sest=§zs, Trem=§TF)",
|
||||
"§%a §rs [§=a>§ A] §sa (§ss) (Sest=§zs, Trem=§TA)",
|
||||
{
|
||||
"f": {
|
||||
"unit": "f",
|
||||
"top": int(info.video_fps.value * info.duration),
|
||||
"a": {
|
||||
"unit": "s",
|
||||
"top": int(info.duration),
|
||||
"precision": 1,
|
||||
"min_width_rate": 9
|
||||
},
|
||||
|
@ -424,9 +424,9 @@ if __name__ == "__main__":
|
|||
out = encode_cmd.get_output()
|
||||
|
||||
if out:
|
||||
if b"frame=" in out:
|
||||
frame_id = re.findall(b"frame= *(\d+) ", out)[0]
|
||||
pb.set("f", int(frame_id))
|
||||
if b"time=" in out:
|
||||
t = aux.parse_time(out)
|
||||
pb.set("a", int(t))
|
||||
|
||||
elif out is None:
|
||||
break
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
major = 1 # VERSION_MAJOR_IDENTIFIER
|
||||
minor = 112 # VERSION_MINOR_IDENTIFIER
|
||||
# VERSION_LAST_MM 1.112
|
||||
patch = 1 # VERSION_PATCH_IDENTIFIER
|
||||
patch = 2 # VERSION_PATCH_IDENTIFIER
|
||||
str = ".".join(str(v) for v in (major, minor, patch))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue