control parser verbosity
This commit is contained in:
@@ -8,7 +8,7 @@ import parse
|
|||||||
from ansi import cursor
|
from ansi import cursor
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
__version__ = 1.1
|
__version__ = 1.2
|
||||||
|
|
||||||
|
|
||||||
class Chopper:
|
class Chopper:
|
||||||
@@ -53,10 +53,19 @@ class Progress:
|
|||||||
self.input_size = "NA"
|
self.input_size = "NA"
|
||||||
self.outputs = []
|
self.outputs = []
|
||||||
self.output = "NA"
|
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):
|
def parse(self, line):
|
||||||
|
|
||||||
if not self.parse_frame(line):
|
if not self.parse_frame(line):
|
||||||
|
if self.verbosity_level == 3:
|
||||||
print(line.rstrip())
|
print(line.rstrip())
|
||||||
self.parse_input(line)
|
self.parse_input(line)
|
||||||
self.parse_output(line)
|
self.parse_output(line)
|
||||||
@@ -166,6 +175,8 @@ class Progress:
|
|||||||
self.framedata["projected_size"] = "NA"
|
self.framedata["projected_size"] = "NA"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
msg = ""
|
||||||
|
if self.verbosity_level > 1:
|
||||||
msg = """{cl}==== Q to exit ===============
|
msg = """{cl}==== Q to exit ===============
|
||||||
{cl}Input: {input_file}
|
{cl}Input: {input_file}
|
||||||
{cl}Output: {output_file}
|
{cl}Output: {output_file}
|
||||||
@@ -196,6 +207,14 @@ class Progress:
|
|||||||
cl=cursor.erase_line(),
|
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.write(msg)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -253,14 +272,23 @@ def ask_for_overwrite(commands, path):
|
|||||||
return commands
|
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():
|
def main():
|
||||||
commands = sys.argv[1:]
|
commands = sys.argv[1:]
|
||||||
if len(commands) == 1:
|
if len(commands) == 1:
|
||||||
if commands[0] == "-h":
|
if commands[0] == "-h":
|
||||||
print(
|
help_exit()
|
||||||
"This command passes all arguments to FFMPEG, and parses output to readable format with progress"
|
if len(commands) == 0:
|
||||||
)
|
help_exit()
|
||||||
sys.exit(0)
|
|
||||||
try:
|
try:
|
||||||
has_overwrite = parse_overwrite(commands)
|
has_overwrite = parse_overwrite(commands)
|
||||||
if not has_overwrite:
|
if not has_overwrite:
|
||||||
|
|||||||
Reference in New Issue
Block a user