Skip to content

Commit

Permalink
Merge pull request beetbox#5052 from Maxr1998/advanced-rewrite-more-c…
Browse files Browse the repository at this point in the history
…orresponding-field-rewrites

advancedrewrite: Apply same rewrite to more corresponding album fields
  • Loading branch information
sampsyo authored Dec 15, 2023
2 parents d456166 + 41719d7 commit b803d84
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions beetsplug/advancedrewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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)
)

Expand Down

0 comments on commit b803d84

Please sign in to comment.