Skip to content

Commit f0f87cc

Browse files
authored
Fix the no_convert option of the convert plugin stopping conversion when there is only a partial match. (#5376)
I was running the `convert` plugin with the following config: ``` no_convert: samplerate:..48000 bitdepth:..16 ``` but anything that was 24/48 was also not being converted, this was due to the code returning `False` for `should_transcode` if any part of the query matches, rather than considering the whole query. This meant that `bitdepth:...16` was being ignored. I have changed this so the `no_convert` value is considered as one query.
2 parents f8b1071 + 4b78abd commit f0f87cc

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

beetsplug/convert.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,20 @@ def get_format(fmt=None):
8484

8585
return (command.encode("utf-8"), extension.encode("utf-8"))
8686

87+
def in_no_convert(item: Item) -> bool:
88+
no_convert_query = config["convert"]["no_convert"].as_str()
8789

90+
if no_convert_query:
91+
query, _ = parse_query_string(no_convert_query, Item)
92+
return query.match(item)
93+
else:
94+
return False
95+
8896
def should_transcode(item, fmt):
8997
"""Determine whether the item should be transcoded as part of
9098
conversion (i.e., its bitrate is high or it has the wrong format).
9199
"""
92-
no_convert_queries = config["convert"]["no_convert"].as_str_seq()
93-
if no_convert_queries:
94-
for query_string in no_convert_queries:
95-
query, _ = parse_query_string(query_string, Item)
96-
if query.match(item):
97-
return False
98-
if (
100+
if in_no_convert(item) or (
99101
config["convert"]["never_convert_lossy_files"]
100102
and item.format.lower() not in LOSSLESS_FORMATS
101103
):

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ Bug fixes:
4747
* :doc:`plugins/lyrics`: Update ``tekstowo`` backend to fetch lyrics directly
4848
since recent updates to their website made it unsearchable.
4949
:bug:`5456`
50+
* :doc:`plugins/convert`: Fixed the convert plugin ``no_convert`` option so
51+
that it no longer treats "and" and "or" queries the same. To maintain
52+
previous behaviour add commas between your query keywords. For help see
53+
:ref:`combiningqueries`.
5054

5155
For packagers:
5256

test/plugins/test_convert.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
import re
1919
import sys
2020
import unittest
21+
import pytest
2122

2223
from mediafile import MediaFile
2324

2425
from beets import util
26+
from beetsplug import convert
27+
from beets.library import Item
2528
from beets.test import _common
2629
from beets.test.helper import (
2730
AsIsImporterMixin,
@@ -335,3 +338,22 @@ def test_transcode_from_lossy_prevented(self):
335338
self.run_convert_path(item.path)
336339
converted = os.path.join(self.convert_dest, b"converted.ogg")
337340
self.assertNoFileTag(converted, "mp3")
341+
342+
343+
class TestNoConvert:
344+
"""Test the effect of the `no_convert` option."""
345+
346+
@pytest.mark.parametrize(
347+
"config_value, should_skip",
348+
[
349+
("", False),
350+
("bitrate:320", False),
351+
("bitrate:320 format:ogg", False),
352+
("bitrate:320 , format:ogg", True),
353+
],
354+
)
355+
356+
def test_no_convert_skip(self, config_value, should_skip):
357+
item = Item(format="ogg", bitrate=256)
358+
convert.config["convert"]["no_convert"] = config_value
359+
assert convert.in_no_convert(item) == should_skip

0 commit comments

Comments
 (0)