From 68c2f96c7082adbc19e43fc24e84295e1b7f6d26 Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Tue, 5 Aug 2025 07:48:57 +0200 Subject: [PATCH] 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. --- beetsplug/lastgenre/__init__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index 9860879a5..067fa80e7 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -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