Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions beetsplug/discogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,10 @@ def get_album_info(self, result: Release) -> AlbumInfo | None:
mediums = [t["medium"] for t in tracks]
country = result.data.get("country")
data_url = result.data.get("uri")
styles: list[str] = result.data.get("styles") or []
genres: list[str] = result.data.get("genres") or []
# we swap genre and style since discogs genres are more general and
# styles more specific
styles: list[str] = result.data.get("genres") or []
genres: list[str] = result.data.get("styles") or []

if self.config["append_style_genre"]:
genres.extend(styles)
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Bug fixes
- :ref:`import-cmd` Fix ``albumartists_sort`` (and related fields) incorrectly
prepending the full combined artist credit as the first element for
multi-artist releases. :bug:`6470`
- :doc:`plugins/discogs`: Store specific Discogs styles in beets ``genres`` and
broader Discogs genres in the ``style`` field. When
:conf:`plugins.discogs:append_style_genre` is enabled, the broader Discogs
genres are also appended to the ``genres`` list. :bug:`6390`

..
For plugin developers
Expand Down
18 changes: 12 additions & 6 deletions docs/plugins/discogs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,22 @@ Default
.. conf:: append_style_genre
:default: no

Appends the Discogs style (if found) to the ``genres`` tag. This can be
useful if you want more granular genres to categorize your music. For
example, a release in Discogs might have a genre of "Electronic" and a style
of "Techno": enabling this setting would append "Techno" to the ``genres``
list.
Appends broader Discogs styles to the ``genres`` list in addition to the
specific Discogs genres already stored there. beets stores specific Discogs
genres in ``genres`` and broader Discogs styles in ``style``. Enabling this
setting keeps ``style`` unchanged and expands ``genres`` with the broader
style values too.

For example, a release in Discogs might have a broader genre of
"Electronic" and a specific style of "Techno": by default, beets would
store ``style`` as "Electronic" and ``genres`` as ["Techno"]. With this
setting enabled, ``genres`` would become ["Electronic", "Techno"].

.. conf:: separator
:default: ", "

How to join multiple style values from Discogs into a string.
How to join the broader Discogs style values into the ``style`` field
string.

.. versionchanged:: 2.7.0

Expand Down
15 changes: 8 additions & 7 deletions test/plugins/test_discogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ def _make_release(self, tracks=None):
"qty": 1,
}
],
"styles": ["STYLE1", "STYLE2"],
"genres": ["GENRE1", "GENRE2"],
# genres and styles are reversed in Discogs
"genres": ["STYLE1", "STYLE2"],
"styles": ["GENRE1", "GENRE2"],
"labels": [
{
"name": "LABEL NAME",
Expand Down Expand Up @@ -363,27 +364,27 @@ def test_default_genre_style_settings(self):
release = self._make_release_from_positions(["1", "2"])

d = DiscogsPlugin().get_album_info(release)
assert d.genres == ["GENRE1", "GENRE2"]
assert d.style == "STYLE1, STYLE2"
assert d.genres == ["GENRE1", "GENRE2"]

def test_append_style_to_genre(self):
"""Test appending style to genre if config enabled"""
config["discogs"]["append_style_genre"] = True
release = self._make_release_from_positions(["1", "2"])

d = DiscogsPlugin().get_album_info(release)
assert d.genres == ["GENRE1", "GENRE2", "STYLE1", "STYLE2"]
assert d.style == "STYLE1, STYLE2"
assert d.genres == ["GENRE1", "GENRE2", "STYLE1", "STYLE2"]

def test_append_style_to_genre_no_style(self):
def test_append_style_to_genre_no_styles(self):
"""Test nothing appended to genre if style is empty"""
config["discogs"]["append_style_genre"] = True
release = self._make_release_from_positions(["1", "2"])
release.data["styles"] = []
release.data["genres"] = []

d = DiscogsPlugin().get_album_info(release)
assert d.genres == ["GENRE1", "GENRE2"]
assert d.style is None
assert d.genres == ["GENRE1", "GENRE2"]

def test_strip_disambiguation(self):
"""Test removing disambiguation from all disambiguated fields."""
Expand Down
Loading