mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-19 23:44:01 +01:00
update Beets
This commit is contained in:
@@ -19,9 +19,8 @@ formats.
|
||||
import re
|
||||
from collections import defaultdict
|
||||
|
||||
from beets import library, ui
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets import ui
|
||||
from beets import library
|
||||
|
||||
|
||||
def rewriter(field, rules):
|
||||
@@ -29,6 +28,7 @@ def rewriter(field, rules):
|
||||
with the given rewriting rules. ``rules`` must be a list of
|
||||
(pattern, replacement) pairs.
|
||||
"""
|
||||
|
||||
def fieldfunc(item):
|
||||
value = item._values_fixed[field]
|
||||
for pattern, replacement in rules:
|
||||
@@ -37,6 +37,7 @@ def rewriter(field, rules):
|
||||
return replacement
|
||||
# Not activated; return original value.
|
||||
return value
|
||||
|
||||
return fieldfunc
|
||||
|
||||
|
||||
@@ -55,15 +56,16 @@ class RewritePlugin(BeetsPlugin):
|
||||
except ValueError:
|
||||
raise ui.UserError("invalid rewrite specification")
|
||||
if fieldname not in library.Item._fields:
|
||||
raise ui.UserError("invalid field name (%s) in rewriter" %
|
||||
fieldname)
|
||||
self._log.debug('adding template field {0}', key)
|
||||
raise ui.UserError(
|
||||
"invalid field name (%s) in rewriter" % fieldname
|
||||
)
|
||||
self._log.debug("adding template field {0}", key)
|
||||
pattern = re.compile(pattern.lower())
|
||||
rules[fieldname].append((pattern, value))
|
||||
if fieldname == 'artist':
|
||||
if fieldname == "artist":
|
||||
# Special case for the artist field: apply the same
|
||||
# rewrite for "albumartist" as well.
|
||||
rules['albumartist'].append((pattern, value))
|
||||
rules["albumartist"].append((pattern, value))
|
||||
|
||||
# Replace each template field with the new rewriter function.
|
||||
for fieldname, fieldrules in rules.items():
|
||||
|
||||
Reference in New Issue
Block a user