mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 04:55:10 +01:00
create seperate in_no_convert function, update tests
This commit is contained in:
parent
2e6e1809e3
commit
4b78abd939
2 changed files with 26 additions and 57 deletions
|
|
@ -84,17 +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_query = config["convert"]["no_convert"].as_str()
|
if in_no_convert(item) or (
|
||||||
if no_convert_query:
|
|
||||||
query, _ = parse_query_string(no_convert_query, 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
|
||||||
):
|
):
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
@ -337,57 +340,20 @@ class NeverConvertLossyFilesTest(ConvertTestCase, ConvertCommand):
|
||||||
self.assertNoFileTag(converted, "mp3")
|
self.assertNoFileTag(converted, "mp3")
|
||||||
|
|
||||||
|
|
||||||
@_common.slow_test()
|
class TestNoConvert:
|
||||||
class NoConvertTest(ConvertTestCase, ConvertCommand):
|
|
||||||
"""Test the effect of the `no_convert` option."""
|
"""Test the effect of the `no_convert` option."""
|
||||||
|
|
||||||
def setUp(self):
|
@pytest.mark.parametrize(
|
||||||
super().setUp()
|
"config_value, should_skip",
|
||||||
|
[
|
||||||
|
("", False),
|
||||||
|
("bitrate:320", False),
|
||||||
|
("bitrate:320 format:ogg", False),
|
||||||
|
("bitrate:320 , format:ogg", True),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
self.convert_dest = os.path.join(self.temp_dir, b"convert_dest")
|
def test_no_convert_skip(self, config_value, should_skip):
|
||||||
self.config["convert"] = {
|
item = Item(format="ogg", bitrate=256)
|
||||||
"dest": self.convert_dest,
|
convert.config["convert"]["no_convert"] = config_value
|
||||||
"no_convert": "format:OGG",
|
assert convert.in_no_convert(item) == should_skip
|
||||||
"paths": {"default": "converted"},
|
|
||||||
"format": "mp3",
|
|
||||||
"formats": {
|
|
||||||
"mp3": self.tagged_copy_cmd("mp3"),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
def test_no_transcode_when_no_convert_set(self):
|
|
||||||
[item] = self.add_item_fixtures(ext="ogg")
|
|
||||||
with control_stdin("y"):
|
|
||||||
self.run_convert_path(item.path)
|
|
||||||
converted = os.path.join(self.convert_dest, b"converted.mp3")
|
|
||||||
self.assertNotExists(converted)
|
|
||||||
|
|
||||||
def test_no_transcode_when_and_query_no_convert_set(self):
|
|
||||||
self.config["convert"]["no_convert"] = "format:OGG bitrate:..256"
|
|
||||||
[item] = self.add_item_fixtures(ext="ogg")
|
|
||||||
item.bitrate = 128
|
|
||||||
item.store()
|
|
||||||
with control_stdin("y"):
|
|
||||||
self.run_convert_path(item.path)
|
|
||||||
converted = os.path.join(self.convert_dest, b"converted.mp3")
|
|
||||||
self.assertNotExists(converted)
|
|
||||||
|
|
||||||
def test_transcode_when_and_query_no_convert_set_partial_match(self):
|
|
||||||
self.config["convert"]["no_convert"] = "format:OGG bitrate:..256"
|
|
||||||
[item] = self.add_item_fixtures(ext="ogg")
|
|
||||||
item.bitrate = 320
|
|
||||||
item.store()
|
|
||||||
with control_stdin("y"):
|
|
||||||
self.run_convert_path(item.path)
|
|
||||||
converted = os.path.join(self.convert_dest, b"converted.mp3")
|
|
||||||
self.assertExists(converted)
|
|
||||||
|
|
||||||
def test_no_transcode_when_or_query_no_convert_set_partial_match(self):
|
|
||||||
self.config["convert"]["no_convert"] = "format:OGG , bitrate:..256"
|
|
||||||
[item] = self.add_item_fixtures(ext="ogg")
|
|
||||||
item.bitrate = 320
|
|
||||||
item.store()
|
|
||||||
with control_stdin("y"):
|
|
||||||
self.run_convert_path(item.path)
|
|
||||||
converted = os.path.join(self.convert_dest, b"converted.mp3")
|
|
||||||
self.assertNotExists(converted)
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue