mirror of
https://github.com/beetbox/beets.git
synced 2025-12-24 09:33:46 +01:00
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:
parent
5d333dca3b
commit
68c2f96c70
1 changed files with 12 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue