Fixed metaflac bug, added -y option

This commit is contained in:
Jamie Hardt
2024-06-30 22:32:16 -07:00
parent 1fe9fea85c
commit b19f6dc4ed
3 changed files with 14 additions and 6 deletions

View File

@@ -11,20 +11,20 @@ import inspect
from mfbatch.util import readline_with_escaped_newlines from mfbatch.util import readline_with_escaped_newlines
import mfbatch.metaflac as flac import mfbatch.metaflac as flac
from mfbatch.commands import BatchfileParser, CommandEnv from mfbatch.commands import BatchfileParser
from tqdm import tqdm from tqdm import tqdm
# import readline # import readline
def execute_batch_list(batch_list_path: str, dry_run: bool): def execute_batch_list(batch_list_path: str, dry_run: bool, interactive: bool):
with open(batch_list_path, mode='r') as f: with open(batch_list_path, mode='r') as f:
parser = BatchfileParser() parser = BatchfileParser()
parser.dry_run = dry_run parser.dry_run = dry_run
for line, line_no in readline_with_escaped_newlines(f): for line, line_no in readline_with_escaped_newlines(f):
if len(line) > 0: if len(line) > 0:
parser._handle_line(line, line_no) parser._handle_line(line, line_no, interactive)
def create_batch_list(command_file: str): def create_batch_list(command_file: str):
@@ -79,6 +79,9 @@ def main():
help="use batch list FILE for reading and writing instead " help="use batch list FILE for reading and writing instead "
"of the default \"MFBATCH_LIST\"", "of the default \"MFBATCH_LIST\"",
default='MFBATCH_LIST') default='MFBATCH_LIST')
op.add_option('-y', '--yes', default=False, action='store_true',
dest='yes', help="automatically confirm all prompts, "
"inhibits interactive editing in -W mode")
op.add_option('--help-commands', action='store_true', default=False, op.add_option('--help-commands', action='store_true', default=False,
dest='help_commands', dest='help_commands',
help='print a list of available commands for batch lists ' help='print a list of available commands for batch lists '
@@ -113,7 +116,9 @@ def main():
if options.write: if options.write:
mode_given = True mode_given = True
execute_batch_list(options.batchfile, dry_run=options.dry_run) execute_batch_list(options.batchfile,
dry_run=options.dry_run,
interactive=not options.yes)
if mode_given == False: if mode_given == False:
op.print_usage() op.print_usage()

View File

@@ -115,7 +115,7 @@ they appear in the batchfile.
self.dry_run = True self.dry_run = True
self.env = CommandEnv() self.env = CommandEnv()
def _handle_line(self, line:str, lineno: int, interactive: bool = True): def _handle_line(self, line:str, lineno: int, interactive: bool):
if line.startswith(self.COMMAND_LEADER): if line.startswith(self.COMMAND_LEADER):
self._handle_command(line.lstrip(self.COMMAND_LEADER), lineno) self._handle_command(line.lstrip(self.COMMAND_LEADER), lineno)
elif line.startswith(self.COMMENT_LEADER): elif line.startswith(self.COMMENT_LEADER):

View File

@@ -61,6 +61,9 @@ def write_metadata(path: str, data: FlacMetadata,
for k in data.keys(): for k in data.keys():
key = sanatize_key(k) key = sanatize_key(k)
val = sanatize_value(data[k]) val = sanatize_value(data[k])
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], insert_job = run([metaflac_path, "--import-tags-from=-", path],