fixed bugs

This commit is contained in:
Jamie Hardt
2024-06-24 21:44:00 -07:00
parent 458716a0a0
commit 02bdde9bae

View File

@@ -53,7 +53,7 @@ class CommandEnv:
self.incr = []
def process_command(metadatums: dict, line: str, dry_run: bool):
def handle_command(metadatums: dict, line: str, dry_run: bool):
commandline = line.lstrip(COMMAND_PROCHAR).rstrip("\n")
args = shlex.split(commandline)
command = args[0]
@@ -85,7 +85,7 @@ def process_command(metadatums: dict, line: str, dry_run: bool):
sys.stderr.write(f"Unrecognized command line: {line}\n")
def process_file(metadatums: dict, line: str, dry_run: bool):
def process_flac_file(metadatums: dict, line: str, dry_run: bool):
line = line.rstrip("\n")
if dry_run:
sys.stderr.write(f"Would process file: {line}\n")
@@ -107,39 +107,39 @@ def execute_batch_list(batch_list_path: str, dry_run: bool):
continue
elif line.startswith(COMMAND_PROCHAR):
process_command(metadatums, line, dry_run)
handle_command(metadatums, line, dry_run)
elif line == "\n":
continue
else:
process_file(metadatums, line, dry_run)
process_flac_file(metadatums, line, dry_run)
def create_cwd_batch_list(command_file: str):
metadatums = {}
with open(command_file, mode='w') as f:
f.write("# mfbatch\n\n")
metaflac_command = [METAFLAC_PATH, '--list']
metadatums = {}
preflight = len(list(iglob('./**/*.flac', recursive=True)))
for path in tqdm(iglob('./**/*.flac', recursive=True),
total=preflight):
result = run(metaflac_command + [path], capture_output=True)
this_file_metadata = {}
for line in result.stdout.decode('utf-8').splitlines():
m = match(r'^\s+comment\[\d\]: ([A-Z]+)=(.*)$', line)
m = match(r'^\s+comment\[\d\]: ([A-Za-z]+)=(.*)$', line)
if m is not None:
this_file_metadata[m[1]] = m[2]
for this_key in this_file_metadata.keys():
if this_key not in metadatums:
f.write(f":set {this_key} "
"{shlex.quote(this_file_metadata[this_key])}\n")
f"{shlex.quote(this_file_metadata[this_key])}\n")
metadatums[this_key] = this_file_metadata[this_key]
else:
if this_file_metadata[this_key] != metadatums[this_key]:
f.write(f":set {this_key} "
"{shlex.quote(this_file_metadata[this_key])}"
f"{shlex.quote(this_file_metadata[this_key])}"
"\n")
metadatums[this_key] = this_file_metadata[this_key]
@@ -155,9 +155,9 @@ def create_cwd_batch_list(command_file: str):
def main():
op = OptionParser(usage="%prog [-c] [-W] [options]")
op.add_option('-c', '--create',
action='store_true',
help='Create a new list')
op.add_option('-c', '--create',
action='store_true',
help='Create a new list')
op.add_option('-W', '--write', default=False,
action='store_true',
help="Execute batch list, write to files")
@@ -177,17 +177,15 @@ def main():
if options.path is not None:
os.chdir(options.path)
command_file = options.batchfile
if options.create:
create_cwd_batch_list(command_file)
create_cwd_batch_list(options.batchfile)
if options.edit:
editor_command = [os.getenv('EDITOR'), command_file]
editor_command = [os.getenv('EDITOR'), options.batchfile]
run(editor_command)
if options.write:
execute_batch_list(command_file, dry_run=True)
execute_batch_list(options.batchfile, dry_run=True)
if __name__ == "__main__":