mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +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())
|
blacklist[section].append(line.strip())
|
||||||
if self.config["extended_debug"]:
|
if self.config["extended_debug"]:
|
||||||
self._log.debug("Blacklist: {}", blacklist)
|
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
|
@property
|
||||||
def sources(self) -> tuple[str, ...]:
|
def sources(self) -> tuple[str, ...]:
|
||||||
|
|
@ -339,7 +346,7 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
||||||
# Check global forbidden patterns
|
# Check global forbidden patterns
|
||||||
if "*" in self.blacklist:
|
if "*" in self.blacklist:
|
||||||
for pattern in self.blacklist["*"]:
|
for pattern in self.blacklist["*"]:
|
||||||
if re.search(pattern, genre):
|
if pattern.search(genre):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Check artist-specific forbidden patterns
|
# Check artist-specific forbidden patterns
|
||||||
|
|
@ -347,7 +354,7 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
||||||
artist = artist.lower()
|
artist = artist.lower()
|
||||||
if artist in self.blacklist:
|
if artist in self.blacklist:
|
||||||
for pattern in self.blacklist[artist]:
|
for pattern in self.blacklist[artist]:
|
||||||
if re.search(pattern, genre):
|
if pattern.search(genre):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue