From 6355de96d86cb4b0187e96ce81828ea2d7082ee5 Mon Sep 17 00:00:00 2001 From: Bob Swift Date: Tue, 9 Apr 2024 12:03:17 -0600 Subject: [PATCH] Trap invalid regex error. Clean up log entries. --- plugins/genre_mapper/__init__.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/plugins/genre_mapper/__init__.py b/plugins/genre_mapper/__init__.py index 2ca4d717..7e72ce5f 100644 --- a/plugins/genre_mapper/__init__.py +++ b/plugins/genre_mapper/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2022-2023 Bob Swift (rdswift) +# Copyright (C) 2022-2024 Bob Swift (rdswift) # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -28,8 +28,8 @@

Please see the user guide on GitHub for more information. ''' -PLUGIN_VERSION = '0.5' -PLUGIN_API_VERSIONS = ['2.0', '2.1', '2.2', '2.3', '2.6', '2.7', '2.8', '2.9'] +PLUGIN_VERSION = '0.6' +PLUGIN_API_VERSIONS = ['2.0', '2.1', '2.2', '2.3', '2.6', '2.7', '2.8', '2.9', '2.10', '2.11'] PLUGIN_LICENSE = "GPL-2.0" PLUGIN_LICENSE_URL = "https://www.gnu.org/licenses/gpl-2.0.txt" @@ -147,21 +147,24 @@ def track_genre_mapper(album, metadata, *args): if not config.setting[OPT_MATCH_ENABLED]: return if 'genre' not in metadata or not metadata['genre']: - log.debug("%s: No genres found for: \"%s\"", PLUGIN_NAME, metadata['title'],) + log.debug('%s: No genres found for: "%s"', PLUGIN_NAME, metadata['title'],) return genre_joiner = config.setting[OPT_GENRE_SEPARATOR] if config.setting[OPT_GENRE_SEPARATOR] else MULTI_VALUED_JOINER genres = set() metadata_genres = str(metadata['genre']).split(genre_joiner) for genre in metadata_genres: for (original, replacement) in GenreMappingPairs.pairs: - if genre and re.search(original, genre, re.IGNORECASE): - genre = replacement - if config.setting[OPT_MATCH_FIRST]: - break + try: + if genre and re.search(original, genre, re.IGNORECASE): + genre = replacement + if config.setting[OPT_MATCH_FIRST]: + break + except re.error: + log.error('%s: Invalid regular expression ignored: "%s"', PLUGIN_NAME, original,) if genre: genres.add(genre.title()) genres = sorted(genres) - log.debug("{0}: Genres updated from {1} to {2}".format(PLUGIN_NAME, metadata_genres, genres,)) + log.debug('%s: Genres updated from %s to %s', PLUGIN_NAME, metadata_genres, genres,) metadata['genre'] = genres