library: Allow overriding global id3v23 option in write()

This commit is contained in:
Jan Holthuis 2019-02-14 15:53:32 +01:00
parent bc5b15f277
commit 305bb64086

View file

@ -611,7 +611,7 @@ class Item(LibModel):
self.path = read_path
def write(self, path=None, tags=None):
def write(self, path=None, tags=None, id3v23=None):
"""Write the item's metadata to a media file.
All fields in `_media_fields` are written to disk according to
@ -623,6 +623,9 @@ class Item(LibModel):
`tags` is a dictionary of additional metadata the should be
written to the file. (These tags need not be in `_media_fields`.)
`id3v23` will override the global `id3v23` config option if it is
set to something other than `None`.
Can raise either a `ReadError` or a `WriteError`.
"""
if path is None:
@ -630,6 +633,9 @@ class Item(LibModel):
else:
path = normpath(path)
if id3v23 is None:
id3v23 = beets.config['id3v23'].get(bool)
# Get the data to write to the file.
item_tags = dict(self)
item_tags = {k: v for k, v in item_tags.items()
@ -640,8 +646,7 @@ class Item(LibModel):
# Open the file.
try:
mediafile = MediaFile(syspath(path),
id3v23=beets.config['id3v23'].get(bool))
mediafile = MediaFile(syspath(path), id3v23=id3v23)
except UnreadableFileError as exc:
raise ReadError(path, exc)