From bc5b15f27757c92a410956e7e4f388aeabd82900 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Thu, 14 Feb 2019 15:52:55 +0100 Subject: [PATCH 1/6] library: Pass try_write() kwargs directly to write() This avoids duplication of the kwargs and their default values. --- beets/library.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beets/library.py b/beets/library.py index 1e46fe5ef..82ba4141d 100644 --- a/beets/library.py +++ b/beets/library.py @@ -657,14 +657,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) From 305bb640862d978fdeee0aa09c768ac95acd14c7 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Thu, 14 Feb 2019 15:53:32 +0100 Subject: [PATCH 2/6] library: Allow overriding global id3v23 option in write() --- beets/library.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/beets/library.py b/beets/library.py index 82ba4141d..16db1e974 100644 --- a/beets/library.py +++ b/beets/library.py @@ -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) From 53b63443fbb1a48341025c941b479e401f2c13d4 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Thu, 14 Feb 2019 23:32:40 +0100 Subject: [PATCH 3/6] art: Allow overriding id3v23 in embed_item() --- beets/art.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beets/art.py b/beets/art.py index 979a6f722..4a9ea58c7 100644 --- a/beets/art.py +++ b/beets/art.py @@ -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, From 7afeb9b2ace75c3d9d00e5f6858989fa763b755a Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Thu, 14 Feb 2019 19:18:02 +0100 Subject: [PATCH 4/6] convert: Add id3v23 config option to convert plugin --- beetsplug/convert.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/beetsplug/convert.py b/beetsplug/convert.py index 3c9080d1f..303563a7a 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -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, From 057904648732fb949886b63ddf4bd03d5e9d56ad Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Thu, 14 Feb 2019 23:37:35 +0100 Subject: [PATCH 5/6] docs: Add new id3v23 config option to convert plugin documentation --- docs/plugins/convert.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/plugins/convert.rst b/docs/plugins/convert.rst index a631f7891..1a487cdee 100644 --- a/docs/plugins/convert.rst +++ b/docs/plugins/convert.rst @@ -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 From 72f837b0cc3ca3ceacaa3e41203db80e40f76de2 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Fri, 15 Feb 2019 13:35:26 +0100 Subject: [PATCH 6/6] docs: Add changelog entry regarding convert plugin's id3v23 option --- docs/changelog.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 2e9b751fe..b44c0e817 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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