Skip to content

Commit af6def0

Browse files
Carson JonesCarson Jones
authored andcommitted
fetchart: handle sources config given as plain string
When the 'sources' config is a plain string (e.g. "sources: filesystem" rather than "sources: [filesystem]"), confuse 2.2.0's Pairs template iterates over individual characters instead of treating it as a single source name. This is because Pairs no longer inherits StrSeq's string-to-list normalization. Normalize the config value to a list before calling as_pairs() so both forms work correctly. Fixes #6336
1 parent f203bc5 commit af6def0

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

beetsplug/fetchart.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,13 @@ def __init__(self) -> None:
14121412
if s_cls.available(self._log, self.config)
14131413
for c in s_cls.VALID_MATCHING_CRITERIA
14141414
]
1415+
# When 'sources' is given as a plain string (e.g. "sources: filesystem"
1416+
# instead of "sources: [filesystem]"), confuse's Pairs template
1417+
# iterates over individual characters instead of treating it as a
1418+
# single-item list. Normalize to a list first via as_str_seq().
1419+
raw_sources = self.config["sources"].get()
1420+
if isinstance(raw_sources, str):
1421+
self.config["sources"].set(raw_sources.split())
14151422
sources = sanitize_pairs(
14161423
self.config["sources"].as_pairs(default_value="*"),
14171424
available_sources,

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Bug fixes
2222
- :ref:`replace`: Made ``drive_sep_replace`` regex logic more precise to prevent
2323
edge-case mismatches (e.g., a song titled "1:00 AM" would incorrectly be
2424
considered a Windows drive path).
25+
- :doc:`plugins/fetchart`: Fix ``sources`` config given as a plain string
26+
(e.g. ``sources: filesystem``) being parsed character-by-character instead of
27+
as a single source name. :bug:`6336`
2528
- :doc:`plugins/fish`: Fix AttributeError. :bug:`6340`
2629
- :ref:`import-cmd` Autotagging by explicit release or recording IDs now keeps
2730
candidates from all enabled metadata sources instead of dropping matches when

test/plugins/test_art.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,3 +1047,28 @@ def test_px(self):
10471047
def test_percent(self):
10481048
self._load_with_config("0% 0.00% 5.1% 5% 100%".split(), False)
10491049
self._load_with_config("00% 1.234% foo5% 100.1%".split(), True)
1050+
1051+
1052+
class SourcesConfigTest(unittest.TestCase):
1053+
"""Test that the 'sources' config option handles both list and plain
1054+
string values correctly.
1055+
"""
1056+
1057+
def test_sources_as_list(self):
1058+
config["fetchart"]["sources"] = ["filesystem"]
1059+
plugin = fetchart.FetchArtPlugin()
1060+
assert len(plugin.sources) == 1
1061+
assert isinstance(plugin.sources[0], fetchart.FileSystem)
1062+
1063+
def test_sources_as_string(self):
1064+
config["fetchart"]["sources"] = "filesystem"
1065+
plugin = fetchart.FetchArtPlugin()
1066+
assert len(plugin.sources) == 1
1067+
assert isinstance(plugin.sources[0], fetchart.FileSystem)
1068+
1069+
def test_sources_as_space_separated_string(self):
1070+
config["fetchart"]["sources"] = "filesystem coverart"
1071+
plugin = fetchart.FetchArtPlugin()
1072+
ids = [type(s).ID for s in plugin.sources]
1073+
assert "filesystem" in ids
1074+
assert "coverart" in ids

0 commit comments

Comments
 (0)