From 55e4917df31f862eac9ae81ec55a2061ca9df48e Mon Sep 17 00:00:00 2001 From: Joseph Heyburn Date: Wed, 2 Mar 2022 22:04:36 +0000 Subject: [PATCH 1/3] discogs: allow style to be appended to genre - Adds a configuration that, when enabled, will append the style to genre - Rationale is to have more verbose genres in genre tag of players that only support genre --- beetsplug/discogs.py | 9 ++++++++- docs/changelog.rst | 1 + docs/plugins/discogs.rst | 6 ++++++ test/test_discogs.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 8c950c521..3c9d16673 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')) + + if self.config['append_style_genre'] and style: + genre = self.config['separator'].as_str() \ + .join([self.format(result.data.get('genres')), style]) + else: + genre = self.format(result.data.get('genres')) + 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..b4d0bec1a 100644 --- a/docs/plugins/discogs.rst +++ b/docs/plugins/discogs.rst @@ -76,6 +76,12 @@ 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 style (if found) to the genre tag, useful if you would like more granular genre styles added to music file tags + Default: ``false`` + + 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__) From 4bde4d082d1a58c6e9a4279d837b06b7a432dbf4 Mon Sep 17 00:00:00 2001 From: Joseph Heyburn Date: Thu, 3 Mar 2022 10:03:31 +0000 Subject: [PATCH 2/3] discogs: allow style to be appended to genre - Added more verbose documentation to `append_style_genre` - Refactor based on code review --- beetsplug/discogs.py | 6 +++--- docs/plugins/discogs.rst | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 3c9d16673..875842f83 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -319,12 +319,12 @@ class DiscogsPlugin(BeetsPlugin): country = result.data.get('country') data_url = result.data.get('uri') style = self.format(result.data.get('styles')) + base_genre = self.format(result.data.get('genres')) if self.config['append_style_genre'] and style: - genre = self.config['separator'].as_str() \ - .join([self.format(result.data.get('genres')), style]) + genre = self.config['separator'].as_str().join([base_genre, style]) else: - genre = self.format(result.data.get('genres')) + genre = base_genre discogs_albumid = self.extract_release_id(result.data.get('uri')) diff --git a/docs/plugins/discogs.rst b/docs/plugins/discogs.rst index b4d0bec1a..d23e4a9c2 100644 --- a/docs/plugins/discogs.rst +++ b/docs/plugins/discogs.rst @@ -79,7 +79,10 @@ This option is useful when importing classical music. Other configurations available under ``discogs:`` are: - **append_style_genre**: Appends the style (if found) to the genre tag, useful if you would like more granular genre styles added to music file tags + e.g. A release in Discogs has 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 genre and style responses from Discogs into a string + Default: ``", "`` Troubleshooting From e1d19c3a3f2c891383230366adfdeba9b14f9253 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Thu, 3 Mar 2022 11:17:07 +0100 Subject: [PATCH 3/3] Docs refinement --- docs/plugins/discogs.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/plugins/discogs.rst b/docs/plugins/discogs.rst index d23e4a9c2..1ed2dfc93 100644 --- a/docs/plugins/discogs.rst +++ b/docs/plugins/discogs.rst @@ -78,10 +78,10 @@ This option is useful when importing classical music. Other configurations available under ``discogs:`` are: -- **append_style_genre**: Appends the style (if found) to the genre tag, useful if you would like more granular genre styles added to music file tags - e.g. A release in Discogs has 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" +- **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 genre and style responses from Discogs into a string +- **separator**: How to join multiple genre and style values from Discogs into a string. Default: ``", "``