This commit is contained in:
Jamie Hardt
2024-07-01 21:04:50 -07:00
parent 12ad66e327
commit 35480978e4
4 changed files with 55 additions and 62 deletions

View File

@@ -17,6 +17,7 @@ from mfbatch.commands import BatchfileParser
from tqdm import tqdm
# import readline
def execute_batch_list(batch_list_path: str, dry_run: bool, interactive: bool):
with open(batch_list_path, mode='r') as f:
parser = BatchfileParser()
@@ -127,5 +128,3 @@ def main():
if __name__ == "__main__":
main()

View File

@@ -21,6 +21,7 @@ class UnrecognizedCommandError(Exception):
self.command = command
self.line = line
class CommandArgumentError(Exception):
command: str
line: int
@@ -110,12 +111,11 @@ they appear in the batchfile.
COMMAND_LEADER = ':'
COMMENT_LEADER = '#'
def __init__(self):
self.dry_run = True
self.env = CommandEnv()
def _handle_line(self, line:str, lineno: int, interactive: bool):
def _handle_line(self, line: str, lineno: int, interactive: bool):
if line.startswith(self.COMMAND_LEADER):
self._handle_command(line.lstrip(self.COMMAND_LEADER), lineno)
elif line.startswith(self.COMMENT_LEADER):
@@ -125,8 +125,8 @@ they appear in the batchfile.
def _handle_command(self, line, lineno):
args = shlex.split(line)
actions = [member for member in dir(self) \
if not member.startswith('_')]
actions = [member for member in dir(self)
if not member.startswith('_')]
if args[0] in actions:
try:
@@ -158,8 +158,8 @@ they appear in the batchfile.
value = self.env.metadatums[key]
LINE_LEN = int(shutil.get_terminal_size()[0]) - 32
value_lines = [value[i:i+LINE_LEN] for i in \
range(0,len(value), LINE_LEN)]
value_lines = [value[i:i+LINE_LEN] for i in
range(0, len(value), LINE_LEN)]
for l in value_lines:
if key:
@@ -273,7 +273,7 @@ they appear in the batchfile.
inp = args[1]
pattern = args[2]
repl = args[3]
self.env.set_pattern(key,inp,pattern, repl)
self.env.set_pattern(key, inp, pattern, repl)
def d(self, args):
"""
@@ -282,7 +282,3 @@ they appear in the batchfile.
"""
val = args[0]
self.env.set_once('DESCRIPTION', val)

View File

@@ -34,7 +34,7 @@ def sanatize_value(v: str) -> str:
newlines, which are not supported by this tool.
"""
return v.translate(str.maketrans('\n',' '))
return v.translate(str.maketrans('\n', ' '))
def read_metadata(path: str, metaflac_path=METAFLAC_PATH) -> FlacMetadata:
@@ -64,9 +64,8 @@ def write_metadata(path: str, data: FlacMetadata,
if key.startswith('_'):
continue
metadatum_f = metadatum_f + f"{key}={val}\n"
metadatum_f = metadatum_f + f"{key}={val}\n"
insert_job = run([metaflac_path, "--import-tags-from=-", path],
input=metadatum_f.encode('utf-8'))
insert_job.check_returncode()

View File

@@ -19,4 +19,3 @@ def readline_with_escaped_newlines(f):
else:
yield line, line_no
line = ''