txtp-segmenter: tweaks

This commit is contained in:
bnnm 2023-02-26 00:18:01 +01:00
parent d07aa75d67
commit 9a2d2c0a7a

View File

@ -28,7 +28,7 @@ def parse():
)
parser = argparse.ArgumentParser(description=description, epilog=epilog, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("files", help="files to match")
parser.add_argument("files", help="files to match", nargs="+")
parser.add_argument("-n","--name", help="generated txtp name (auto from 'files' by default)\nMay use regex groups like '\\1.ogg' when used with filter-include")
parser.add_argument("-fi","--filter-include", help="include files matched with regex and ignore rest")
parser.add_argument("-fe","--filter-exclude", help="exclude files matched with regex and keep rest")
@ -41,6 +41,7 @@ def parse():
parser.add_argument("-cv","--command-volume", help="sets volume")
parser.add_argument("-c","--command", help="sets any command (free text)")
parser.add_argument("-ci","--command-inline", help="sets any inline command (free text)")
parser.add_argument("-m","--multi", help="only write txtp that have multiple results", action='store_true')
return parser.parse_args()
@ -102,7 +103,10 @@ def main():
args.p_exclude = re.compile(args.filter_exclude, re.IGNORECASE)
# get target files
files = glob.glob(args.files)
files = []
for file in args.files:
print(file)
files += glob.glob(file)
# process matches and add to output list
txtps = {}
@ -123,6 +127,8 @@ def main():
# list info
for name, segments in txtps.items():
if args.multi and len(segments) <= 1:
continue
print("file: " + name)
for segment in segments:
print(" " + segment)
@ -133,6 +139,8 @@ def main():
# write resulting files
for name, segments in txtps.items():
len_segments = len(segments)
if args.multi and len_segments <= 1:
continue
with open(name,"w+") as ftxtp:
for i, segment in enumerate(segments):
command_inline = ''