diff --git a/README.md b/README.md index cfe83e0..3d3d204 100644 --- a/README.md +++ b/README.md @@ -150,4 +150,4 @@ types = [".mp3", ".flac"] tags = "genre" ``` -`plugins` limits which plugins run (`hash//` is listed as `hashdoubleslash`), `types` overrides the file types a plugin handles, and `id3.map` additionally reads an audio tag (here `GENRE`) into a category. +`plugins` limits which plugins run (`hash//` is listed as `hashdoubleslash`), `types` overrides the file types a plugin handles (`write` ignores types the plugin does not support), and `id3.map` additionally reads an audio tag (here `GENRE`) into a category. diff --git a/orvanitag/orvani.py b/orvanitag/orvani.py index 3067456..b3ff49d 100644 --- a/orvanitag/orvani.py +++ b/orvanitag/orvani.py @@ -695,12 +695,8 @@ class OrvaniTag: suffixes = plugin.TYPES # Load the plugin's defaults if plugin_name in config: # Check for local folder config overrides if 'types' in config[plugin_name]: - suffixes = config[plugin_name]['types'] - for suffix in suffixes: - if not suffix in plugin.TYPES: - suffixes.remove(suffix) - if not suffixes: - suffixes = plugin.TYPES + # Only types the plugin can write, falling back to its defaults + suffixes = [suffix for suffix in config[plugin_name]['types'] if suffix in plugin.TYPES] or plugin.TYPES o.file = Path(filename) if o.file.suffix in suffixes: diff --git a/tests/test_plugins.py b/tests/test_plugins.py index aaa923c..50ee583 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -143,3 +143,11 @@ def test_cmd_scan_defaults_to_current_folder(cwd, monkeypatch): monkeypatch.setattr(sys, 'argv', ['otag', 's']) main() assert (cwd / 'sub' / orvani.CONTEXT_FILE).read_text() == 'doc.pdf --- #lofi\n' + + +def test_write_ignores_configured_types_the_plugin_cannot_handle(cwd): + (cwd / orvani.CONFIG_FILE).write_text('[pdf]\ntypes = [".xyz", ".abc", ".pdf"]\n') + (cwd / 'doc.abc').write_text('not a pdf') + OrvaniTag().add('doc.abc', '#lofi') + assert OrvaniTag().write_metadata('doc.abc', 'pdf') == [4, ['.pdf'], 'pdf', True] + assert (cwd / 'doc.abc').read_text() == 'not a pdf'