Skip to content

Commit

Permalink
Merge pull request #376 from rdswift/2.0
Browse files Browse the repository at this point in the history
Genre Mapper invalid regex exception handling
  • Loading branch information
phw authored May 12, 2024
2 parents 45870b4 + 6355de9 commit e859f90
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions plugins/genre_mapper/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -28,8 +28,8 @@
<br /><br />
Please see the <a href="https://github.com/rdswift/picard-plugins/blob/2.0_RDS_Plugins/plugins/genre_mapper/docs/README.md">user guide</a> 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"

Expand Down Expand Up @@ -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


Expand Down

0 comments on commit e859f90

Please sign in to comment.