From 41719d7b499cb612f1b008cdefb07039dd0c20ad Mon Sep 17 00:00:00 2001 From: Maxr1998 Date: Fri, 15 Dec 2023 17:23:40 +0100 Subject: [PATCH] advancedrewrite: Apply same rewrite to more corresponding album fields --- beetsplug/advancedrewrite.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/beetsplug/advancedrewrite.py b/beetsplug/advancedrewrite.py index 6b7fad1a2c..639aa5247c 100644 --- a/beetsplug/advancedrewrite.py +++ b/beetsplug/advancedrewrite.py @@ -88,6 +88,14 @@ def __init__(self): ) ) + # Used to apply the same rewrite to the corresponding album field. + corresponding_album_fields = { + "artist": "albumartist", + "artists": "albumartists", + "artist_sort": "albumartist_sort", + "artists_sort": "albumartists_sort", + } + # Gather all the rewrite rules for each field. simple_rules = defaultdict(list) advanced_rules = defaultdict(list) @@ -117,10 +125,11 @@ def __init__(self): ) pattern = re.compile(pattern.lower()) simple_rules[fieldname].append((pattern, value)) - if fieldname == "artist": - # Special case for the artist field: apply the same - # rewrite for "albumartist" as well. - simple_rules["albumartist"].append((pattern, value)) + + # Apply the same rewrite to the corresponding album field. + if fieldname in corresponding_album_fields: + album_fieldname = corresponding_album_fields[fieldname] + simple_rules[album_fieldname].append((pattern, value)) else: # Advanced syntax match = rule["match"] @@ -160,18 +169,11 @@ def __init__(self): ) advanced_rules[fieldname].append((query, replacement)) - # Special case for the artist(s) field: - # apply the same rewrite for "albumartist(s)" as well. - if fieldname == "artist": - advanced_rules["albumartist"].append( - (query, replacement) - ) - elif fieldname == "artists": - advanced_rules["albumartists"].append( - (query, replacement) - ) - elif fieldname == "artist_sort": - advanced_rules["albumartist_sort"].append( + + # Apply the same rewrite to the corresponding album field. + if fieldname in corresponding_album_fields: + album_fieldname = corresponding_album_fields[fieldname] + advanced_rules[album_fieldname].append( (query, replacement) )