mirror of
https://github.com/beetbox/beets.git
synced 2026-01-06 07:53:40 +01:00
fromfilename: simplify
This commit is contained in:
parent
b8f01f0cfa
commit
9607b258a5
1 changed files with 10 additions and 10 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue