mirror of
https://github.com/beetbox/beets.git
synced 2026-01-01 13:33:02 +01:00
fuzzy_search: simplifiy some nested code
This commit is contained in:
parent
e092af2b2f
commit
1e48317e51
1 changed files with 15 additions and 23 deletions
|
|
@ -35,17 +35,15 @@ def is_match(query, item, album=False, verbose=False, threshold=0.7):
|
|||
values = [item.artist, item.album, item.title]
|
||||
|
||||
s = max(fuzzy_score(query.lower(), i.lower()) for i in values)
|
||||
if s >= threshold:
|
||||
return (True, s) if verbose else True
|
||||
if verbose:
|
||||
return (s >= threshold, s)
|
||||
else:
|
||||
return (False, s) if verbose else False
|
||||
return s >= threshold
|
||||
|
||||
|
||||
def fuzzy_list(lib, config, opts, args):
|
||||
query = decargs(args)
|
||||
path = opts.path
|
||||
fmt = opts.format
|
||||
verbose = opts.verbose
|
||||
threshold = float(opts.threshold)
|
||||
|
||||
if fmt is None:
|
||||
|
|
@ -61,24 +59,18 @@ def fuzzy_list(lib, config, opts, args):
|
|||
else:
|
||||
objs = lib.items()
|
||||
|
||||
if opts.album:
|
||||
for album in objs:
|
||||
if is_match(query, album, album=True, threshold=threshold):
|
||||
if path:
|
||||
print_(album.item_dir())
|
||||
else:
|
||||
print_(album.evaluate_template(template))
|
||||
if verbose:
|
||||
print is_match(query, album, album=True, verbose=True)[1]
|
||||
else:
|
||||
for item in objs:
|
||||
if is_match(query, item, threshold=threshold):
|
||||
if path:
|
||||
print_(item.path)
|
||||
else:
|
||||
print_(item.evaluate_template(template, lib))
|
||||
if verbose:
|
||||
print is_match(query, item, verbose=True)[1]
|
||||
items = filter(lambda i: is_match(query, i, album=opts.album,
|
||||
threshold=threshold), objs)
|
||||
for i in items:
|
||||
if opts.path:
|
||||
print_(i.item_dir() if opts.album else i.path)
|
||||
elif opts.album:
|
||||
print_(i.evaluate_template(template))
|
||||
else:
|
||||
print_(i.evaluate_template(template, lib))
|
||||
if opts.verbose:
|
||||
print(is_match(query, i, album=opts.album, verbose=True)[1])
|
||||
|
||||
|
||||
fuzzy_cmd = Subcommand('fuzzy',
|
||||
help='list items using fuzzy matching')
|
||||
|
|
|
|||
Loading…
Reference in a new issue