Merge pull request #3144 from Holzhaus/add-id3v23-to-convert

Add id3v23 option to convert plugin
This commit is contained in:
Adrian Sampson 2019-02-15 09:51:46 -07:00 committed by GitHub
commit 69fbba1eed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 9 deletions

View file

@ -51,7 +51,8 @@ def get_art(log, item):
def embed_item(log, item, imagepath, maxwidth=None, itempath=None,
compare_threshold=0, ifempty=False, as_album=False):
compare_threshold=0, ifempty=False, as_album=False,
id3v23=None):
"""Embed an image into the item's media file.
"""
# Conditions and filters.
@ -80,7 +81,7 @@ def embed_item(log, item, imagepath, maxwidth=None, itempath=None,
image.mime_type)
return
item.try_write(path=itempath, tags={'images': [image]})
item.try_write(path=itempath, tags={'images': [image]}, id3v23=id3v23)
def embed_album(log, album, maxwidth=None, quiet=False,

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)
@ -657,14 +662,14 @@ class Item(LibModel):
self.mtime = self.current_mtime()
plugins.send('after_write', item=self, path=path)
def try_write(self, path=None, tags=None):
def try_write(self, *args, **kwargs):
"""Calls `write()` but catches and logs `FileOperationError`
exceptions.
Returns `False` an exception was caught and `True` otherwise.
"""
try:
self.write(path, tags)
self.write(*args, **kwargs)
return True
except FileOperationError as exc:
log.error(u"{0}", exc)

View file

@ -116,6 +116,7 @@ class ConvertPlugin(BeetsPlugin):
u'pretend': False,
u'threads': util.cpu_count(),
u'format': u'mp3',
u'id3v23': u'inherit',
u'formats': {
u'aac': {
u'command': u'ffmpeg -i $source -y -vn -acodec aac '
@ -316,8 +317,12 @@ class ConvertPlugin(BeetsPlugin):
if pretend:
continue
id3v23 = self.config['id3v23'].as_choice([True, False, 'inherit'])
if id3v23 == 'inherit':
id3v23 = None
# Write tags from the database to the converted file.
item.try_write(path=converted)
item.try_write(path=converted, id3v23=id3v23)
if keep_new:
# If we're keeping the transcoded file, read it again (after
@ -332,7 +337,7 @@ class ConvertPlugin(BeetsPlugin):
self._log.debug(u'embedding album art from {}',
util.displayable_path(album.artpath))
art.embed_item(self._log, item, album.artpath,
itempath=converted)
itempath=converted, id3v23=id3v23)
if keep_new:
plugins.send('after_convert', item=item,

View file

@ -37,6 +37,10 @@ New features:
relevant releases according to the :ref:`preferred` configuration options.
Thanks to :user:`archer4499`.
:bug:`3017`
* :doc:`/plugins/convert`: The plugin now has a ``id3v23`` option that allows
to override the global ``id3v23`` option.
Thanks to :user:`Holzhaus`.
:bug:`3104`
* A new ``aunique`` configuration option allows setting default options
for the :ref:`aunique` template function.
* The ``albumdisambig`` field no longer includes the MusicBrainz release group

View file

@ -68,6 +68,8 @@ file. The available options are:
- **dest**: The directory where the files will be converted (or copied) to.
Default: none.
- **embed**: Embed album art in converted items. Default: ``yes``.
- **id3v23**: Can be used to override the global ``id3v23`` option. Default:
``inherit``.
- **max_bitrate**: All lossy files with a higher bitrate will be
transcoded and those with a lower bitrate will simply be copied. Note that
this does not guarantee that all converted files will have a lower