Skip to content

Commit 8c846c3

Browse files
committed
tagging: allow nulling singleton fields
1 parent 9c85547 commit 8c846c3

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

beets/autotag/__init__.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ def __getattr__(name: str):
119119
def _apply_metadata(
120120
info: AlbumInfo | TrackInfo,
121121
db_obj: Album | Item,
122-
nullable_fields: Sequence[str] = [],
122+
null_fields: bool = True,
123123
):
124124
"""Set the db_obj's metadata to match the info."""
125-
special_fields = SPECIAL_FIELDS[
126-
"album" if isinstance(info, AlbumInfo) else "track"
127-
]
125+
key = "album" if isinstance(info, AlbumInfo) else "track"
126+
special_fields = set(SPECIAL_FIELDS[key])
127+
nullable_fields = set(config["overwrite_null"][key].as_str_seq())
128128

129129
for field, value in info.items():
130130
# We only overwrite fields that are not already hardcoded.
@@ -133,7 +133,7 @@ def _apply_metadata(
133133

134134
# Don't overwrite fields with empty values unless the
135135
# field is explicitly allowed to be overwritten.
136-
if value is None and field not in nullable_fields:
136+
if null_fields and value is None and field not in nullable_fields:
137137
continue
138138

139139
db_obj[field] = value
@@ -206,7 +206,7 @@ def apply_item_metadata(item: Item, track_info: TrackInfo):
206206

207207
def apply_album_metadata(album_info: AlbumInfo, album: Album):
208208
"""Set the album's metadata to match the AlbumInfo object."""
209-
_apply_metadata(album_info, album)
209+
_apply_metadata(album_info, album, null_fields=False)
210210
correct_list_fields(album)
211211

212212

@@ -320,16 +320,7 @@ def apply_metadata(
320320
# Track alt.
321321
item.track_alt = track_info.track_alt
322322

323-
_apply_metadata(
324-
album_info,
325-
item,
326-
nullable_fields=config["overwrite_null"]["album"].as_str_seq(),
327-
)
328-
329-
_apply_metadata(
330-
track_info,
331-
item,
332-
nullable_fields=config["overwrite_null"]["track"].as_str_seq(),
333-
)
323+
_apply_metadata(album_info, item)
324+
_apply_metadata(track_info, item)
334325

335326
correct_list_fields(item)

0 commit comments

Comments
 (0)