lastgenre: Handle blacklist regex compile errors

Fall back to literal strings if a regex compile fails. This
automagically supports strings as well as regex patterns in the
blacklist.
This commit is contained in:
J0J0 Todos 2025-08-05 07:48:57 +02:00
parent 5d333dca3b
commit 68c2f96c70

View file

@ -218,9 +218,18 @@ class LastGenrePlugin(plugins.BeetsPlugin):
# Compile regex patterns
compiled_blacklist = defaultdict(list)
for artist, patterns in blacklist.items():
compiled_blacklist[artist] = [
re.compile(pattern) for pattern in patterns
]
compiled_patterns = []
for pattern in patterns:
try:
# Try to compile as regex first
compiled_patterns.append(re.compile(pattern, re.IGNORECASE))
except re.error:
# If it fails, escape it and treat as literal string
escaped_pattern = re.escape(pattern)
compiled_patterns.append(
re.compile(escaped_pattern, re.IGNORECASE)
)
compiled_blacklist[artist] = compiled_patterns
return compiled_blacklist
@property