Remove tag when an empty string is passed
This commit is contained in:
parent
74c133bcb9
commit
4c0766b2c1
1 changed files with 10 additions and 9 deletions
17
flacinfo.py
17
flacinfo.py
|
@ -38,11 +38,11 @@ class NoSuchTag(Exception):
|
||||||
|
|
||||||
|
|
||||||
class MetaflacError(Exception):
|
class MetaflacError(Exception):
|
||||||
""" Raised when an invocation of metaflac failed. """
|
"""Raised when an invocation of metaflac failed."""
|
||||||
|
|
||||||
|
|
||||||
def argparser():
|
def argparser():
|
||||||
""" Parses the arguments from sys.argv """
|
"""Parses the arguments from sys.argv"""
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Edit flac files' metadata",
|
description="Edit flac files' metadata",
|
||||||
epilog=(
|
epilog=(
|
||||||
|
@ -66,7 +66,7 @@ def argparser():
|
||||||
|
|
||||||
|
|
||||||
def is_flac_file(path):
|
def is_flac_file(path):
|
||||||
""" Checks whether `path` refers to an existing, writeable flac file """
|
"""Checks whether `path` refers to an existing, writeable flac file"""
|
||||||
if not os.path.isfile(path) or not os.access(path, os.W_OK):
|
if not os.path.isfile(path) or not os.access(path, os.W_OK):
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
@ -92,13 +92,14 @@ def make_metaflac_args(in_args):
|
||||||
arg_name = VORBIS_ARG_NAME[arg]
|
arg_name = VORBIS_ARG_NAME[arg]
|
||||||
|
|
||||||
out_args.append("--remove-tag={}".format(arg_name))
|
out_args.append("--remove-tag={}".format(arg_name))
|
||||||
|
if arg_val:
|
||||||
out_args.append("--set-tag={}={}".format(arg_name, arg_val))
|
out_args.append("--set-tag={}={}".format(arg_name, arg_val))
|
||||||
|
|
||||||
return out_args
|
return out_args
|
||||||
|
|
||||||
|
|
||||||
def edit_flac(args):
|
def edit_flac(args):
|
||||||
""" Perfoms the requested edition operations """
|
"""Perfoms the requested edition operations"""
|
||||||
metaflac_args = make_metaflac_args(args)
|
metaflac_args = make_metaflac_args(args)
|
||||||
metaflac_args += args["file"]
|
metaflac_args += args["file"]
|
||||||
metaflac_args.insert(0, "metaflac")
|
metaflac_args.insert(0, "metaflac")
|
||||||
|
@ -113,7 +114,7 @@ def edit_flac(args):
|
||||||
|
|
||||||
|
|
||||||
def reverse_tag(vorbis_tag):
|
def reverse_tag(vorbis_tag):
|
||||||
""" Reverses a Vorbis tag to an argument name """
|
"""Reverses a Vorbis tag to an argument name"""
|
||||||
for tag in VORBIS_ARG_NAME:
|
for tag in VORBIS_ARG_NAME:
|
||||||
if VORBIS_ARG_NAME[tag] == vorbis_tag:
|
if VORBIS_ARG_NAME[tag] == vorbis_tag:
|
||||||
return tag
|
return tag
|
||||||
|
@ -121,7 +122,7 @@ def reverse_tag(vorbis_tag):
|
||||||
|
|
||||||
|
|
||||||
def get_tags(path):
|
def get_tags(path):
|
||||||
""" Retrieves the relevant tags for a single file """
|
"""Retrieves the relevant tags for a single file"""
|
||||||
metaflac_args = ["metaflac"]
|
metaflac_args = ["metaflac"]
|
||||||
for tag in VORBIS_ARG_NAME:
|
for tag in VORBIS_ARG_NAME:
|
||||||
metaflac_args += ["--show-tag", VORBIS_ARG_NAME[tag]]
|
metaflac_args += ["--show-tag", VORBIS_ARG_NAME[tag]]
|
||||||
|
@ -150,7 +151,7 @@ def get_tags(path):
|
||||||
|
|
||||||
|
|
||||||
def show_tags(path):
|
def show_tags(path):
|
||||||
""" Shows the relevant tags already present in the given flac file """
|
"""Shows the relevant tags already present in the given flac file"""
|
||||||
tags = get_tags(path)
|
tags = get_tags(path)
|
||||||
print("File: {}".format(path))
|
print("File: {}".format(path))
|
||||||
|
|
||||||
|
@ -161,7 +162,7 @@ def show_tags(path):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
""" Entrypoint function """
|
"""Entrypoint function"""
|
||||||
args = vars(argparser())
|
args = vars(argparser())
|
||||||
|
|
||||||
has_errors = False
|
has_errors = False
|
||||||
|
|
Loading…
Reference in a new issue