control parser verbosity

This commit is contained in:
Ville Rantanen
2023-01-12 17:21:42 +02:00
parent 6afa9aa6db
commit e2d4f9a60d

View File

@@ -8,7 +8,7 @@ import parse
from ansi import cursor
from datetime import datetime
__version__ = 1.1
__version__ = 1.2
class Chopper:
@@ -53,10 +53,19 @@ class Progress:
self.input_size = "NA"
self.outputs = []
self.output = "NA"
self.verbosity = os.getenv("PARSER_VERBOSITY", "").upper()
try:
self.verbosity_level = ["NONE", "PROGRESS", "STATUS", "ALL"].index(
self.verbosity
)
except ValueError:
self.verbosity_level = 3
def parse(self, line):
if not self.parse_frame(line):
if self.verbosity_level == 3:
print(line.rstrip())
self.parse_input(line)
self.parse_output(line)
@@ -166,17 +175,19 @@ class Progress:
self.framedata["projected_size"] = "NA"
try:
msg = ""
if self.verbosity_level > 1:
msg = """{cl}==== Q to exit ===============
{cl}Input: {input_file}
{cl}Output: {output_file}
{cl}Progress: {progress}% Elapsed: H{elapsed}
{cl}Finished in: H{left}
{cl}Frame: {frame} = {out_time}
{cl}Source duration: {duration}
{cl}Processing speed: FPS {fps} / {speed}
{cl}Bitrate: {bitrate}
{cl}File size: {total_size}Mb -> {projected_size}Mb (Input: {input_size}Mb)
{cl}{progress_bar}\r{up}""".format(
{cl}Input: {input_file}
{cl}Output: {output_file}
{cl}Progress: {progress}% Elapsed: H{elapsed}
{cl}Finished in: H{left}
{cl}Frame: {frame} = {out_time}
{cl}Source duration: {duration}
{cl}Processing speed: FPS {fps} / {speed}
{cl}Bitrate: {bitrate}
{cl}File size: {total_size}Mb -> {projected_size}Mb (Input: {input_size}Mb)
{cl}{progress_bar}\r{up}""".format(
input_file=self.input,
input_size=self.input_size,
output_file=self.output,
@@ -196,6 +207,14 @@ class Progress:
cl=cursor.erase_line(),
)
if self.verbosity_level == 1:
msg = "{cl}{progress_bar} {progress}%\r".format(
progress_bar=self._progress_bar(self.framedata["percent_done"]),
progress=self.framedata["percent_done"],
up=cursor.up(1),
cl=cursor.erase_line(),
)
sys.stdout.write(msg)
sys.stdout.flush()
except Exception as e:
@@ -220,7 +239,7 @@ class Progress:
def _mbstr(self, b):
try:
return "{:.1f}".format((float(b) / (1024 ** 2)))
return "{:.1f}".format((float(b) / (1024**2)))
except Exception:
return b
@@ -253,14 +272,23 @@ def ask_for_overwrite(commands, path):
return commands
def help_exit():
print(
"""This command passes all arguments to FFMPEG, and parses output to
readable format with progress. Change verbosity with env PARSER_VERBOSITY.
Values are NONE,PROGRESS,STATUS,ALL."""
)
sys.exit(0)
def main():
commands = sys.argv[1:]
if len(commands) == 1:
if commands[0] == "-h":
print(
"This command passes all arguments to FFMPEG, and parses output to readable format with progress"
)
sys.exit(0)
help_exit()
if len(commands) == 0:
help_exit()
try:
has_overwrite = parse_overwrite(commands)
if not has_overwrite: