mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
lastgenre: Precompile blacklist regex patterns
This commit is contained in:
parent
37703cc792
commit
fb65d852c5
1 changed files with 10 additions and 3 deletions
|
|
@ -214,7 +214,14 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
|||
blacklist[section].append(line.strip())
|
||||
if self.config["extended_debug"]:
|
||||
self._log.debug("Blacklist: {}", blacklist)
|
||||
return blacklist
|
||||
|
||||
# Compile regex patterns
|
||||
compiled_blacklist = defaultdict(list)
|
||||
for artist, patterns in blacklist.items():
|
||||
compiled_blacklist[artist] = [
|
||||
re.compile(pattern) for pattern in patterns
|
||||
]
|
||||
return compiled_blacklist
|
||||
|
||||
@property
|
||||
def sources(self) -> tuple[str, ...]:
|
||||
|
|
@ -339,7 +346,7 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
|||
# Check global forbidden patterns
|
||||
if "*" in self.blacklist:
|
||||
for pattern in self.blacklist["*"]:
|
||||
if re.search(pattern, genre):
|
||||
if pattern.search(genre):
|
||||
return True
|
||||
|
||||
# Check artist-specific forbidden patterns
|
||||
|
|
@ -347,7 +354,7 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
|||
artist = artist.lower()
|
||||
if artist in self.blacklist:
|
||||
for pattern in self.blacklist[artist]:
|
||||
if re.search(pattern, genre):
|
||||
if pattern.search(genre):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
|
|
|||
Loading…
Reference in a new issue