From ddc99f45886b43fa744dcefaa1b04ec04ad39e99 Mon Sep 17 00:00:00 2001 From: Sindre Date: Wed, 2 Sep 2026 20:51:09 +0200 Subject: [PATCH 1/3] Normalize digital media in Discogs searches --- beetsplug/discogs/__init__.py | 5 +++++ docs/changelog.rst | 2 ++ docs/plugins/discogs.rst | 3 +++ test/plugins/test_discogs.py | 17 +++++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/beetsplug/discogs/__init__.py b/beetsplug/discogs/__init__.py index abb3f2bef3..1f102e6b73 100644 --- a/beetsplug/discogs/__init__.py +++ b/beetsplug/discogs/__init__.py @@ -311,6 +311,11 @@ def get_search_query_with_filters( value = str(most_common) if tag == "catalognum": value = value.replace(" ", "") + elif tag == "media" and value.casefold() in { + "digital media", + "web", + }: + value = "File" filters[api_field] = value diff --git a/docs/changelog.rst b/docs/changelog.rst index 38e34a6b4d..6002b617f8 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -26,6 +26,8 @@ Bug fixes writes to the item's source file when ``beet convert`` writes the converted file, which previously crashed with a :class:`PermissionError` when the source file was read-only. :bug:`6954` +- :doc:`plugins/discogs`: Normalize ``Digital Media`` and ``WEB`` to Discogs' + ``File`` format when using ``media`` in ``extra_tags`` search filters. .. For plugin developers diff --git a/docs/plugins/discogs.rst b/docs/plugins/discogs.rst index bab62c2748..3f17dece9f 100644 --- a/docs/plugins/discogs.rst +++ b/docs/plugins/discogs.rst @@ -180,6 +180,9 @@ Default * ``media`` * ``year`` + When ``media`` is included, ``Digital Media`` and ``WEB`` are normalized to + Discogs' ``File`` format when constructing the search query. + Example: .. code-block:: yaml diff --git a/test/plugins/test_discogs.py b/test/plugins/test_discogs.py index a31504f62d..cf6699695b 100644 --- a/test/plugins/test_discogs.py +++ b/test/plugins/test_discogs.py @@ -554,6 +554,23 @@ def test_extra_tags_populate_discogs_filters(self): assert filters["catno"] == "ABC123" config["discogs"]["extra_tags"] = [] + @pytest.mark.parametrize( + "media,expected", + [("Digital Media", "File"), ("WEB", "File"), ("Vinyl", "Vinyl")], + ) + def test_extra_tags_normalize_media(self, media, expected): + plugin = DiscogsPlugin() + plugin.config["extra_tags"] = ["media"] + + items = [Item(media=media)] + + _query, filters = plugin.get_search_query_with_filters( + "album", items, "Artist", "Album", False + ) + + assert filters["format"] == expected + config["discogs"]["extra_tags"] = [] + class TestDGSearchResponse(DiscogsTestMixin): @staticmethod From 2fcdc1206ba24ab5b66aa28643f1ceda3b06bc2e Mon Sep 17 00:00:00 2001 From: Sindre Date: Mon, 21 Sep 2026 12:47:34 +0200 Subject: [PATCH 2/3] Normalize Discogs media before plurality --- beetsplug/discogs/__init__.py | 19 +++++++++++-------- test/plugins/test_discogs.py | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/beetsplug/discogs/__init__.py b/beetsplug/discogs/__init__.py index 1f102e6b73..be85378967 100644 --- a/beetsplug/discogs/__init__.py +++ b/beetsplug/discogs/__init__.py @@ -81,6 +81,8 @@ "year": "year", } +MEDIA_FORMAT_ALIASES = {"digital media": "File", "web": "File"} + def parse_release_date( released: str | None, year: int | None @@ -302,20 +304,21 @@ def get_search_query_with_filters( return query, filters for tag, api_field in self.extra_discogs_field_by_tag.items(): - most_common, _count = util.plurality( - item.get(tag) for item in items - ) + values = (item.get(tag) for item in items) + + if tag == "media": + values = ( + MEDIA_FORMAT_ALIASES.get(str(value).casefold(), value) + for value in values + ) + + most_common, _count = util.plurality(values) if most_common is None: continue value = str(most_common) if tag == "catalognum": value = value.replace(" ", "") - elif tag == "media" and value.casefold() in { - "digital media", - "web", - }: - value = "File" filters[api_field] = value diff --git a/test/plugins/test_discogs.py b/test/plugins/test_discogs.py index cf6699695b..41787210ea 100644 --- a/test/plugins/test_discogs.py +++ b/test/plugins/test_discogs.py @@ -571,6 +571,27 @@ def test_extra_tags_normalize_media(self, media, expected): assert filters["format"] == expected config["discogs"]["extra_tags"] = [] + def test_extra_tags_normalize_media_before_plurality(self): + plugin = DiscogsPlugin() + plugin.config["extra_tags"] = ["media"] + + items = [ + Item(media="Digital Media"), + Item(media="Digital Media"), + Item(media="WEB"), + Item(media="WEB"), + Item(media="Vinyl"), + Item(media="Vinyl"), + Item(media="Vinyl"), + ] + + _query, filters = plugin.get_search_query_with_filters( + "album", items, "Artist", "Album", False + ) + + assert filters["format"] == "File" + config["discogs"]["extra_tags"] = [] + class TestDGSearchResponse(DiscogsTestMixin): @staticmethod From 73de5b73faba4cf025e4c1a8902e1cf53a54c23b Mon Sep 17 00:00:00 2001 From: Sindre Date: Mon, 21 Sep 2026 13:22:29 +0200 Subject: [PATCH 3/3] Simplify Discogs media aliases --- beetsplug/discogs/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/beetsplug/discogs/__init__.py b/beetsplug/discogs/__init__.py index be85378967..e06e47d8e1 100644 --- a/beetsplug/discogs/__init__.py +++ b/beetsplug/discogs/__init__.py @@ -81,7 +81,7 @@ "year": "year", } -MEDIA_FORMAT_ALIASES = {"digital media": "File", "web": "File"} +MEDIA_FORMAT_ALIASES = {"digital media", "web"} def parse_release_date( @@ -308,7 +308,9 @@ def get_search_query_with_filters( if tag == "media": values = ( - MEDIA_FORMAT_ALIASES.get(str(value).casefold(), value) + "File" + if str(value).casefold() in MEDIA_FORMAT_ALIASES + else value for value in values )