diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 8c950c521..875842f83 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -57,6 +57,7 @@ class DiscogsPlugin(BeetsPlugin): 'user_token': '', 'separator': ', ', 'index_tracks': False, + 'append_style_genre': False, }) self.config['apikey'].redact = True self.config['apisecret'].redact = True @@ -318,7 +319,13 @@ class DiscogsPlugin(BeetsPlugin): country = result.data.get('country') data_url = result.data.get('uri') style = self.format(result.data.get('styles')) - genre = self.format(result.data.get('genres')) + base_genre = self.format(result.data.get('genres')) + + if self.config['append_style_genre'] and style: + genre = self.config['separator'].as_str().join([base_genre, style]) + else: + genre = base_genre + discogs_albumid = self.extract_release_id(result.data.get('uri')) # Extract information for the optional AlbumInfo fields that are diff --git a/docs/changelog.rst b/docs/changelog.rst index 7135ecb3e..633ddda24 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -12,6 +12,7 @@ New features: :bug:`4101` * Add the item fields ``bitrate_mode``, ``encoder_info`` and ``encoder_settings``. * Add query prefixes ``=`` and ``~``. +* :doc:`/plugins/discogs`: Permit appending style to genre Bug fixes: diff --git a/docs/plugins/discogs.rst b/docs/plugins/discogs.rst index 5aea1ae6b..1ed2dfc93 100644 --- a/docs/plugins/discogs.rst +++ b/docs/plugins/discogs.rst @@ -76,6 +76,15 @@ whereas with ``index_tracks`` disabled you'd get:: This option is useful when importing classical music. +Other configurations available under ``discogs:`` are: + +- **append_style_genre**: Appends the Discogs style (if found) to the genre 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 set the genre to be "Electronic, Techno" (assuming default separator of ``", "``) instead of just "Electronic". + Default: ``false`` +- **separator**: How to join multiple genre and style values from Discogs into a string. + Default: ``", "`` + + Troubleshooting --------------- diff --git a/test/test_discogs.py b/test/test_discogs.py index 4e62e7124..d6825c978 100644 --- a/test/test_discogs.py +++ b/test/test_discogs.py @@ -20,6 +20,8 @@ from test import _common from test._common import Bag from test.helper import capture_log +from beets import config + from beetsplug.discogs import DiscogsPlugin @@ -373,6 +375,33 @@ class DGAlbumInfoTest(_common.TestCase): match = '' self.assertEqual(match, expected) + def test_default_genre_style_settings(self): + """Test genre default settings, genres to genre, styles to style""" + release = self._make_release_from_positions(['1', '2']) + + d = DiscogsPlugin().get_album_info(release) + self.assertEqual(d.genre, 'GENRE1, GENRE2') + self.assertEqual(d.style, 'STYLE1, STYLE2') + + 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) + self.assertEqual(d.genre, 'GENRE1, GENRE2, STYLE1, STYLE2') + self.assertEqual(d.style, 'STYLE1, STYLE2') + + def test_append_style_to_genre_no_style(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'] = [] + + d = DiscogsPlugin().get_album_info(release) + self.assertEqual(d.genre, 'GENRE1, GENRE2') + self.assertEqual(d.style, None) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)