diff --git a/beetsplug/convert.py b/beetsplug/convert.py index fe9d91d25..bb06488f9 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -84,18 +84,20 @@ def get_format(fmt=None): return (command.encode("utf-8"), extension.encode("utf-8")) +def in_no_convert(item: Item) -> bool: + no_convert_query = config["convert"]["no_convert"].as_str() + if no_convert_query: + query, _ = parse_query_string(no_convert_query, Item) + return query.match(item) + else: + return False + def should_transcode(item, fmt): """Determine whether the item should be transcoded as part of conversion (i.e., its bitrate is high or it has the wrong format). """ - no_convert_queries = config["convert"]["no_convert"].as_str_seq() - if no_convert_queries: - for query_string in no_convert_queries: - query, _ = parse_query_string(query_string, Item) - if query.match(item): - return False - if ( + if in_no_convert(item) or ( config["convert"]["never_convert_lossy_files"] and item.format.lower() not in LOSSLESS_FORMATS ): diff --git a/docs/changelog.rst b/docs/changelog.rst index a2e15dd31..3e4266db1 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -47,6 +47,10 @@ Bug fixes: * :doc:`plugins/lyrics`: Update ``tekstowo`` backend to fetch lyrics directly since recent updates to their website made it unsearchable. :bug:`5456` +* :doc:`plugins/convert`: Fixed the convert plugin ``no_convert`` option so + that it no longer treats "and" and "or" queries the same. To maintain + previous behaviour add commas between your query keywords. For help see + :ref:`combiningqueries`. For packagers: diff --git a/test/plugins/test_convert.py b/test/plugins/test_convert.py index 725318eac..9057b2472 100644 --- a/test/plugins/test_convert.py +++ b/test/plugins/test_convert.py @@ -18,10 +18,13 @@ import os.path import re import sys import unittest +import pytest from mediafile import MediaFile from beets import util +from beetsplug import convert +from beets.library import Item from beets.test import _common from beets.test.helper import ( AsIsImporterMixin, @@ -335,3 +338,22 @@ class NeverConvertLossyFilesTest(ConvertTestCase, ConvertCommand): self.run_convert_path(item.path) converted = os.path.join(self.convert_dest, b"converted.ogg") self.assertNoFileTag(converted, "mp3") + + +class TestNoConvert: + """Test the effect of the `no_convert` option.""" + + @pytest.mark.parametrize( + "config_value, should_skip", + [ + ("", False), + ("bitrate:320", False), + ("bitrate:320 format:ogg", False), + ("bitrate:320 , format:ogg", True), + ], + ) + + def test_no_convert_skip(self, config_value, should_skip): + item = Item(format="ogg", bitrate=256) + convert.config["convert"]["no_convert"] = config_value + assert convert.in_no_convert(item) == should_skip