mirror of
https://github.com/beetbox/beets.git
synced 2025-12-07 09:04:33 +01:00
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.
This commit is contained in:
commit
f0f87cc8ca
3 changed files with 35 additions and 7 deletions
|
|
@ -84,18 +84,20 @@ def get_format(fmt=None):
|
||||||
|
|
||||||
return (command.encode("utf-8"), extension.encode("utf-8"))
|
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):
|
def should_transcode(item, fmt):
|
||||||
"""Determine whether the item should be transcoded as part of
|
"""Determine whether the item should be transcoded as part of
|
||||||
conversion (i.e., its bitrate is high or it has the wrong format).
|
conversion (i.e., its bitrate is high or it has the wrong format).
|
||||||
"""
|
"""
|
||||||
no_convert_queries = config["convert"]["no_convert"].as_str_seq()
|
if in_no_convert(item) or (
|
||||||
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 (
|
|
||||||
config["convert"]["never_convert_lossy_files"]
|
config["convert"]["never_convert_lossy_files"]
|
||||||
and item.format.lower() not in LOSSLESS_FORMATS
|
and item.format.lower() not in LOSSLESS_FORMATS
|
||||||
):
|
):
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,10 @@ Bug fixes:
|
||||||
* :doc:`plugins/lyrics`: Update ``tekstowo`` backend to fetch lyrics directly
|
* :doc:`plugins/lyrics`: Update ``tekstowo`` backend to fetch lyrics directly
|
||||||
since recent updates to their website made it unsearchable.
|
since recent updates to their website made it unsearchable.
|
||||||
:bug:`5456`
|
: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:
|
For packagers:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,13 @@ import os.path
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
import pytest
|
||||||
|
|
||||||
from mediafile import MediaFile
|
from mediafile import MediaFile
|
||||||
|
|
||||||
from beets import util
|
from beets import util
|
||||||
|
from beetsplug import convert
|
||||||
|
from beets.library import Item
|
||||||
from beets.test import _common
|
from beets.test import _common
|
||||||
from beets.test.helper import (
|
from beets.test.helper import (
|
||||||
AsIsImporterMixin,
|
AsIsImporterMixin,
|
||||||
|
|
@ -335,3 +338,22 @@ class NeverConvertLossyFilesTest(ConvertTestCase, ConvertCommand):
|
||||||
self.run_convert_path(item.path)
|
self.run_convert_path(item.path)
|
||||||
converted = os.path.join(self.convert_dest, b"converted.ogg")
|
converted = os.path.join(self.convert_dest, b"converted.ogg")
|
||||||
self.assertNoFileTag(converted, "mp3")
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue