From 0028787498190d95bf92a979e5ad4955d6f4e437 Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Sat, 25 May 2024 12:16:04 +0200 Subject: [PATCH 1/4] Check for valid mediafile in convert.py --- beetsplug/convert.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/beetsplug/convert.py b/beetsplug/convert.py index 536acf16e3..9d30825ae9 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -20,6 +20,7 @@ import subprocess import tempfile import threading +import mediafile from string import Template from confuse import ConfigTypeError, Optional @@ -351,6 +352,15 @@ def convert_item( item = yield (item, original, converted) dest = item.destination(basedir=dest_dir, path_formats=path_formats) + # Ensure that desired item is readable before processing it. Needed + # to avoid any side-effect of the conversion (linking, keep_new, + # refresh) if we already know that it will fail. + try: + mf = mediafile.MediaFile(util.syspath(item.path)) + except mediafile.UnreadableFileError as exc: + self._log.error("Could not open file to convert: {0}", exc) + continue + # When keeping the new file in the library, we first move the # current (pristine) file to the destination. We'll then copy it # back to its old path or transcode it to a new path. From 3920235076fc77565653cf105c151ead03183058 Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Sat, 25 May 2024 12:19:53 +0200 Subject: [PATCH 2/4] Update changelog --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 43cdd12555..c5b26c2db4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -519,6 +519,8 @@ Bug fixes: `requests` timeout. * Fix cover art resizing logic to support multiple steps of resizing :bug:`5151` +* :doc:`/plugins/convert`: Fix attempt to convert and perform side-effects if + library file is not readable. For plugin developers: From b3e75b49bd786ceb2cc58d1171e0fe451cd91e2e Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Wed, 3 Jul 2024 12:23:05 +0200 Subject: [PATCH 3/4] Format fix by tox --- beetsplug/convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/convert.py b/beetsplug/convert.py index 9d30825ae9..5e7a2ccf37 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -20,9 +20,9 @@ import subprocess import tempfile import threading -import mediafile from string import Template +import mediafile from confuse import ConfigTypeError, Optional from beets import art, config, plugins, ui, util From ffc665efad69a5a5f973c231f93d798858e17fbf Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Wed, 3 Jul 2024 12:25:22 +0200 Subject: [PATCH 4/4] Fix unused local variable linting error --- beetsplug/convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/convert.py b/beetsplug/convert.py index 5e7a2ccf37..0c50fc73fb 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -356,7 +356,7 @@ def convert_item( # to avoid any side-effect of the conversion (linking, keep_new, # refresh) if we already know that it will fail. try: - mf = mediafile.MediaFile(util.syspath(item.path)) + mediafile.MediaFile(util.syspath(item.path)) except mediafile.UnreadableFileError as exc: self._log.error("Could not open file to convert: {0}", exc) continue