diff --git a/ucsinfer/__main__.py b/ucsinfer/__main__.py index b4cb286..4ca2550 100644 --- a/ucsinfer/__main__.py +++ b/ucsinfer/__main__.py @@ -103,6 +103,11 @@ def recommend(ctx, text, paths, interactive, skip_ucs): catlist = [x.catid for x in inference_ctx.catlist] for path in paths: + _, ext = os.path.splitext(path) + + if ext not in (".wav", ".flac"): + continue + basename = os.path.basename(path) if skip_ucs and parse_ucs(basename, catlist): continue diff --git a/ucsinfer/recommend.py b/ucsinfer/recommend.py index 6c92abd..5378df9 100644 --- a/ucsinfer/recommend.py +++ b/ucsinfer/recommend.py @@ -1,10 +1,13 @@ # recommend.py from re import match + from .inference import InferenceContext +from tabulate import tabulate + def print_recommendation(path: str | None, text: str, ctx: InferenceContext, - interactive_rename: bool): + interactive_rename: bool, recommend_limit=10): """ Print recommendations interactively. @@ -16,7 +19,7 @@ def print_recommendation(path: str | None, text: str, ctx: InferenceContext, `print_recommendation` should be called again with this argument. - if retval[2] is a str, this is the catid the user has selected. """ - recs = ctx.classify_text_ranked(text) + recs = ctx.classify_text_ranked(text, limit=recommend_limit) print("----------") if path: print(f"Path: {path}") @@ -28,7 +31,7 @@ def print_recommendation(path: str | None, text: str, ctx: InferenceContext, print(f"- {i}: {r} ({cat}-{subcat})") if interactive_rename and path is not None: - response = input("#, t [text], ?, q > ") + response = input("(n#), t [text], c [cat], ?, q > ") if m := match(r'^([0-9]+)', response): selection = int(m.group(1)) @@ -43,16 +46,27 @@ def print_recommendation(path: str | None, text: str, ctx: InferenceContext, text = m.group(1) return True, text, None - elif m := match(r'^c (.*)', response): + elif m := match(r'^c (.+)', response): return True, None, m.group(1) + elif m := match(r'^b (.+)', response): + expt = [] + for cat in ctx.catlist: + if cat.catid.startswith(m.group(1)): + expt.append([f"{cat.catid}: ({cat.category}-{cat.subcategory})", + cat.explanations]) + + print(tabulate(expt, maxcolwidths=80)) + return True, text, None + elif response.startswith("?"): print(""" Choices: - Enter recommendation number to rename file, -- "t [text]" to search for new recommendations based on [text] +- "t " to search for new recommendations based on - "p" re-use the last selected cat-id -- "c [cat]" to type in a category by hand +- "c " to type in a category by hand +- "b " browse category list for categories starting with - "?" for this message - "q" to quit - or any other key to skip this file and continue to next file @@ -60,6 +74,8 @@ Choices: return True, text, None elif response.startswith('q'): return (False, None, None) + else: + print() else: return None