From 8fcff5ddc7bfef1394bedc39aa83614a7710d0ee Mon Sep 17 00:00:00 2001 From: Peter Koondial Date: Sun, 5 May 2019 11:11:27 +0200 Subject: [PATCH 01/16] Adding styles to discogs plugin --- beets/autotag/__init__.py | 1 + beets/config_default.yaml | 1 + beets/library.py | 4 +++- beetsplug/discogs.py | 10 +++++++++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index a71b9b0a6..48901f425 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -155,6 +155,7 @@ def apply_metadata(album_info, mapping): 'script', 'language', 'country', + 'style', 'albumstatus', 'albumdisambig', 'releasegroupdisambig', diff --git a/beets/config_default.yaml b/beets/config_default.yaml index cf9ae6bf9..538753bb7 100644 --- a/beets/config_default.yaml +++ b/beets/config_default.yaml @@ -131,6 +131,7 @@ match: track_index: 1.0 track_length: 2.0 track_id: 5.0 + style: 5.0 preferred: countries: [] media: [] diff --git a/beets/library.py b/beets/library.py index 16db1e974..97ae4589c 100644 --- a/beets/library.py +++ b/beets/library.py @@ -436,6 +436,7 @@ class Item(LibModel): 'albumartist_sort': types.STRING, 'albumartist_credit': types.STRING, 'genre': types.STRING, + 'style': types.STRING, 'lyricist': types.STRING, 'composer': types.STRING, 'composer_sort': types.STRING, @@ -495,7 +496,7 @@ class Item(LibModel): } _search_fields = ('artist', 'title', 'comments', - 'album', 'albumartist', 'genre') + 'album', 'albumartist') _types = { 'data_source': types.STRING, @@ -915,6 +916,7 @@ class Album(LibModel): 'albumartist_credit': types.STRING, 'album': types.STRING, 'genre': types.STRING, + 'style': types.STRING, 'year': types.PaddedInt(4), 'month': types.PaddedInt(2), 'day': types.PaddedInt(2), diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 5a2bf57e0..efc9f2b0e 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -302,6 +302,13 @@ class DiscogsPlugin(BeetsPlugin): mediums = [t.medium for t in tracks] country = result.data.get('country') data_url = result.data.get('uri') + style = result.data.get('styles') + if style is None: + self._log.info('Style not Found') + elif len(style) == 0: + return style + else: + style = ' - '.join(sorted(style)) # Extract information for the optional AlbumInfo fields that are # contained on nested discogs fields. @@ -339,7 +346,8 @@ class DiscogsPlugin(BeetsPlugin): day=None, label=label, mediums=len(set(mediums)), artist_sort=None, releasegroup_id=master_id, catalognum=catalogno, script=None, language=None, - country=country, albumstatus=None, media=media, + country=country, style=style, + albumstatus=None, media=media, albumdisambig=None, artist_credit=None, original_year=original_year, original_month=None, original_day=None, data_source='Discogs', From 295efde7b43e1cf389136cae4362d971e93a5a7f Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 5 May 2019 11:23:27 +0200 Subject: [PATCH 02/16] re-adding genre --- beets/library.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beets/library.py b/beets/library.py index 97ae4589c..c7fbe48cf 100644 --- a/beets/library.py +++ b/beets/library.py @@ -496,7 +496,7 @@ class Item(LibModel): } _search_fields = ('artist', 'title', 'comments', - 'album', 'albumartist') + 'album', 'albumartist', 'genre') _types = { 'data_source': types.STRING, From 6ffbd5af45ac88a584c07ee22fa0fbabf5c2a45e Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 5 May 2019 11:44:24 +0200 Subject: [PATCH 03/16] adding styles to hook and returning Style not Defined if no style set --- beets/autotag/hooks.py | 5 +++-- beetsplug/discogs.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index ec7047b7c..f822cdfde 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -79,7 +79,7 @@ class AlbumInfo(object): albumtype=None, va=False, year=None, month=None, day=None, label=None, mediums=None, artist_sort=None, releasegroup_id=None, catalognum=None, script=None, - language=None, country=None, albumstatus=None, media=None, + language=None, country=None, style=None, albumstatus=None, media=None, albumdisambig=None, releasegroupdisambig=None, artist_credit=None, original_year=None, original_month=None, original_day=None, data_source=None, data_url=None): @@ -102,6 +102,7 @@ class AlbumInfo(object): self.script = script self.language = language self.country = country + self.style = style self.albumstatus = albumstatus self.media = media self.albumdisambig = albumdisambig @@ -121,7 +122,7 @@ class AlbumInfo(object): constituent `TrackInfo` objects, are decoded to Unicode. """ for fld in ['album', 'artist', 'albumtype', 'label', 'artist_sort', - 'catalognum', 'script', 'language', 'country', + 'catalognum', 'script', 'language', 'country', 'style', 'albumstatus', 'albumdisambig', 'releasegroupdisambig', 'artist_credit', 'media']: value = getattr(self, fld) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index efc9f2b0e..0865b691b 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -303,8 +303,10 @@ class DiscogsPlugin(BeetsPlugin): country = result.data.get('country') data_url = result.data.get('uri') style = result.data.get('styles') + print('style', style) if style is None: self._log.info('Style not Found') + return "Style not Defined" elif len(style) == 0: return style else: From 851c413976c83080e1cff3afe4a01364afc88461 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 9 Jun 2019 10:37:33 +0200 Subject: [PATCH 04/16] adding config option for seperator and addressing review comments --- beets/config_default.yaml | 1 - beetsplug/discogs.py | 5 ++--- test/test_discogs.py | 3 +++ 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/beets/config_default.yaml b/beets/config_default.yaml index 538753bb7..cf9ae6bf9 100644 --- a/beets/config_default.yaml +++ b/beets/config_default.yaml @@ -131,7 +131,6 @@ match: track_index: 1.0 track_length: 2.0 track_id: 5.0 - style: 5.0 preferred: countries: [] media: [] diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 0865b691b..88e0704d9 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -55,6 +55,7 @@ class DiscogsPlugin(BeetsPlugin): 'tokenfile': 'discogs_token.json', 'source_weight': 0.5, 'user_token': '', + 'separator': u', ' }) self.config['apikey'].redact = True self.config['apisecret'].redact = True @@ -303,14 +304,12 @@ class DiscogsPlugin(BeetsPlugin): country = result.data.get('country') data_url = result.data.get('uri') style = result.data.get('styles') - print('style', style) if style is None: self._log.info('Style not Found') - return "Style not Defined" elif len(style) == 0: return style else: - style = ' - '.join(sorted(style)) + style = self.config['separator'].as_str().join(sorted(style)) # Extract information for the optional AlbumInfo fields that are # contained on nested discogs fields. diff --git a/test/test_discogs.py b/test/test_discogs.py index 8b2eff9f1..4445014be 100644 --- a/test/test_discogs.py +++ b/test/test_discogs.py @@ -45,6 +45,9 @@ class DGAlbumInfoTest(_common.TestCase): 'name': 'FORMAT', 'qty': 1 }], + 'styles': [{ + 'STYLE' + }], 'labels': [{ 'name': 'LABEL NAME', 'catno': 'CATALOG NUMBER', From 6cdd1ab6c1fccd28f9a083e7a16284572921d1dc Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 9 Jun 2019 12:08:07 +0200 Subject: [PATCH 05/16] fixing test --- test/test_discogs.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/test_discogs.py b/test/test_discogs.py index 4445014be..cc97017fe 100644 --- a/test/test_discogs.py +++ b/test/test_discogs.py @@ -45,9 +45,9 @@ class DGAlbumInfoTest(_common.TestCase): 'name': 'FORMAT', 'qty': 1 }], - 'styles': [{ - 'STYLE' - }], + 'styles': [ + 'STYLE1', 'STYLE2' + ], 'labels': [{ 'name': 'LABEL NAME', 'catno': 'CATALOG NUMBER', @@ -59,6 +59,7 @@ class DGAlbumInfoTest(_common.TestCase): for recording in tracks: data['tracklist'].append(recording) + return Bag(data=data, # Make some fields available as properties, as they are # accessed by DiscogsPlugin methods. @@ -84,6 +85,8 @@ class DGAlbumInfoTest(_common.TestCase): tracklist where tracks have the specified `positions`.""" tracks = [self._make_track('TITLE%s' % i, position) for (i, position) in enumerate(positions, start=1)] + release = self._make_release(tracks) + print('release', release) return self._make_release(tracks) def test_parse_media_for_tracks(self): @@ -92,6 +95,7 @@ class DGAlbumInfoTest(_common.TestCase): release = self._make_release(tracks=tracks) d = DiscogsPlugin().get_album_info(release) + print('albumInfo', d.media) t = d.tracks self.assertEqual(d.media, 'FORMAT') self.assertEqual(t[0].media, d.media) From 319e1da727062605b86a4047aaa3d008489eedad Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 9 Jun 2019 12:29:45 +0200 Subject: [PATCH 06/16] fixing tox.ini file to match master --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index e3250bd6b..8736f0f3c 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -envlist = py27-test, py37-test, py38-test, py27-flake8, docs +envlist = py27-test, py37-test, py27-flake8, docs # The exhaustive list of environments is: # envlist = py{27,34,35}-{test,cov}, py{27,34,35}-flake8, docs From 371d978e134314cc22a87a9372cfa99aae06b3b7 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 9 Jun 2019 12:39:21 +0200 Subject: [PATCH 07/16] removing blank line and making line shorter --- beets/autotag/hooks.py | 4 ++-- test/test_discogs.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index f822cdfde..b8e6108b4 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -79,8 +79,8 @@ class AlbumInfo(object): albumtype=None, va=False, year=None, month=None, day=None, label=None, mediums=None, artist_sort=None, releasegroup_id=None, catalognum=None, script=None, - language=None, country=None, style=None, albumstatus=None, media=None, - albumdisambig=None, releasegroupdisambig=None, + language=None, country=None, style=None, albumstatus=None, + media=None, albumdisambig=None, releasegroupdisambig=None, artist_credit=None, original_year=None, original_month=None, original_day=None, data_source=None, data_url=None): self.album = album diff --git a/test/test_discogs.py b/test/test_discogs.py index cc97017fe..403f01da7 100644 --- a/test/test_discogs.py +++ b/test/test_discogs.py @@ -59,7 +59,6 @@ class DGAlbumInfoTest(_common.TestCase): for recording in tracks: data['tracklist'].append(recording) - return Bag(data=data, # Make some fields available as properties, as they are # accessed by DiscogsPlugin methods. From 9789c465aab4f061a49c5391f42204e46a64c9d3 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 9 Jun 2019 12:49:04 +0200 Subject: [PATCH 08/16] removing blank line --- test/test_discogs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_discogs.py b/test/test_discogs.py index 403f01da7..36239d697 100644 --- a/test/test_discogs.py +++ b/test/test_discogs.py @@ -357,7 +357,6 @@ class DGAlbumInfoTest(_common.TestCase): self.assertEqual(d, None) self.assertIn('Release does not contain the required fields', logs[0]) - def suite(): return unittest.TestLoader().loadTestsFromName(__name__) From 77dcd63254b802af806ee07a1b10d2e2f8f78534 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 9 Jun 2019 12:59:32 +0200 Subject: [PATCH 09/16] adding line --- test/test_discogs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_discogs.py b/test/test_discogs.py index 36239d697..403f01da7 100644 --- a/test/test_discogs.py +++ b/test/test_discogs.py @@ -357,6 +357,7 @@ class DGAlbumInfoTest(_common.TestCase): self.assertEqual(d, None) self.assertIn('Release does not contain the required fields', logs[0]) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__) From 5fc21a1e211b8a83a76ebef33b27ddd7f39cd3ec Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 9 Jun 2019 15:39:49 +0200 Subject: [PATCH 10/16] fixing per review comments --- beetsplug/discogs.py | 6 ++++-- test/test_discogs.py | 2 -- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 88e0704d9..ed53d0012 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -304,9 +304,11 @@ class DiscogsPlugin(BeetsPlugin): country = result.data.get('country') data_url = result.data.get('uri') style = result.data.get('styles') + print('style', style) if style is None: - self._log.info('Style not Found') - elif len(style) == 0: + self._log.debug('Style not Found') + elif not style: + print('s', style) return style else: style = self.config['separator'].as_str().join(sorted(style)) diff --git a/test/test_discogs.py b/test/test_discogs.py index 403f01da7..8c9d7a249 100644 --- a/test/test_discogs.py +++ b/test/test_discogs.py @@ -85,7 +85,6 @@ class DGAlbumInfoTest(_common.TestCase): tracks = [self._make_track('TITLE%s' % i, position) for (i, position) in enumerate(positions, start=1)] release = self._make_release(tracks) - print('release', release) return self._make_release(tracks) def test_parse_media_for_tracks(self): @@ -94,7 +93,6 @@ class DGAlbumInfoTest(_common.TestCase): release = self._make_release(tracks=tracks) d = DiscogsPlugin().get_album_info(release) - print('albumInfo', d.media) t = d.tracks self.assertEqual(d.media, 'FORMAT') self.assertEqual(t[0].media, d.media) From 2c49c12166f49f0e3e2736577cc0eeb66863ea12 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 9 Jun 2019 15:44:37 +0200 Subject: [PATCH 11/16] fixing per review comments --- beetsplug/discogs.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index ed53d0012..ad170ca0b 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -304,11 +304,9 @@ class DiscogsPlugin(BeetsPlugin): country = result.data.get('country') data_url = result.data.get('uri') style = result.data.get('styles') - print('style', style) if style is None: self._log.debug('Style not Found') - elif not style: - print('s', style) + elif len(style) == 0: return style else: style = self.config['separator'].as_str().join(sorted(style)) From f0c91b8f45747bae4b6daf354c69bcecf8ff7e30 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 9 Jun 2019 20:01:55 +0200 Subject: [PATCH 12/16] fixing per review comments --- beetsplug/discogs.py | 2 +- test/test_discogs.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index ad170ca0b..e4c82cd14 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -306,7 +306,7 @@ class DiscogsPlugin(BeetsPlugin): style = result.data.get('styles') if style is None: self._log.debug('Style not Found') - elif len(style) == 0: + elif not style: return style else: style = self.config['separator'].as_str().join(sorted(style)) diff --git a/test/test_discogs.py b/test/test_discogs.py index 8c9d7a249..0acf54e8a 100644 --- a/test/test_discogs.py +++ b/test/test_discogs.py @@ -84,7 +84,6 @@ class DGAlbumInfoTest(_common.TestCase): tracklist where tracks have the specified `positions`.""" tracks = [self._make_track('TITLE%s' % i, position) for (i, position) in enumerate(positions, start=1)] - release = self._make_release(tracks) return self._make_release(tracks) def test_parse_media_for_tracks(self): From 55e003a3d4371acec2f04a34378494b8cb4eac38 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 10 Jun 2019 09:11:38 +0200 Subject: [PATCH 13/16] fixing per review comments --- beetsplug/discogs.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index e4c82cd14..69b3746f7 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -303,13 +303,7 @@ class DiscogsPlugin(BeetsPlugin): mediums = [t.medium for t in tracks] country = result.data.get('country') data_url = result.data.get('uri') - style = result.data.get('styles') - if style is None: - self._log.debug('Style not Found') - elif not style: - return style - else: - style = self.config['separator'].as_str().join(sorted(style)) + style = self.format_style(result.data.get('styles')) # Extract information for the optional AlbumInfo fields that are # contained on nested discogs fields. @@ -354,6 +348,15 @@ class DiscogsPlugin(BeetsPlugin): original_day=None, data_source='Discogs', data_url=data_url) + def format_style(self, style): + if style is None: + self._log.debug('Style not Found') + elif not style: + return style + else: + return self.config['separator'].as_str().join(sorted(style)) + + def get_artist(self, artists): """Returns an artist string (all artists) and an artist_id (the main artist) for a list of discogs album or track artists. From 9bdadc5c73cfeebe072e5459f855e55ff6c9b070 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 10 Jun 2019 09:33:10 +0200 Subject: [PATCH 14/16] removing extra line --- beetsplug/discogs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 69b3746f7..bdc2154de 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -356,7 +356,6 @@ class DiscogsPlugin(BeetsPlugin): else: return self.config['separator'].as_str().join(sorted(style)) - def get_artist(self, artists): """Returns an artist string (all artists) and an artist_id (the main artist) for a list of discogs album or track artists. From 7ec1fc934be53d88e20150f9a9aa320a7a8d1cee Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 10 Jun 2019 15:54:19 +0200 Subject: [PATCH 15/16] removing unneeded condition --- beetsplug/discogs.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index bdc2154de..f6197ddba 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -351,8 +351,6 @@ class DiscogsPlugin(BeetsPlugin): def format_style(self, style): if style is None: self._log.debug('Style not Found') - elif not style: - return style else: return self.config['separator'].as_str().join(sorted(style)) From 34c28529a0da0ec8ab0100d13aeac00a1fb34cfe Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 10 Jun 2019 16:41:41 +0200 Subject: [PATCH 16/16] Trigger