control parser verbosity
This commit is contained in:
@@ -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,6 +175,8 @@ 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}
|
||||
@@ -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:
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user