From 9607b258a5e2c091ecbeed4a008ff1c9bbb3be4e Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Fri, 13 Sep 2013 21:14:10 -0700 Subject: [PATCH] fromfilename: simplify --- beetsplug/fromfilename.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/beetsplug/fromfilename.py b/beetsplug/fromfilename.py index ca1cdd68b..2d17e3394 100644 --- a/beetsplug/fromfilename.py +++ b/beetsplug/fromfilename.py @@ -60,13 +60,13 @@ def equal_fields(matchdict, field): def all_matches(names, pattern): - """If all the filenames in the item/filename pair list match the + """If all the filenames in the item/filename mapping match the pattern, return a dictionary mapping the items to dictionaries giving the value for each named subpattern in the match. Otherwise, return None. """ matches = {} - for item, name in names: + for item, name in names.items(): m = re.match(pattern, name, re.IGNORECASE) if m: matches[item] = m.groupdict() @@ -143,16 +143,16 @@ def filename_task(task, session): items = task.items if task.is_album else [task.item] # Look for suspicious (empty or meaningless) titles. - names = [] - missing_titles = 0 - for item in items: - name, _ = os.path.splitext(os.path.basename(item.path)) - names.append((item, name)) - if bad_title(item.title): - missing_titles += 1 + missing_titles = sum(bad_title(i.title) for i in items) - # Look for useful information in the filenames. if missing_titles: + # Get the base filenames (no path or extension). + names = {} + for item in items: + name, _ = os.path.splitext(os.path.basename(item.path)) + names[item] = name + + # Look for useful information in the filenames. for pattern in PATTERNS: d = all_matches(names, pattern) if d: