From 90cf579ee39bbdaad467baf83e8316c84bb30525 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 16 Jun 2019 21:55:35 +0200 Subject: [PATCH 01/11] adding genre, released_date and discogs_release_id --- beets/autotag/__init__.py | 3 +++ beets/autotag/hooks.py | 11 +++++++---- beets/library.py | 7 +++++++ beetsplug/beatport.py | 1 + beetsplug/discogs.py | 20 +++++++++++++------- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index 48901f425..5d116c7f2 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -156,6 +156,9 @@ def apply_metadata(album_info, mapping): 'language', 'country', 'style', + 'genre', + 'discogs_release_id', + 'released_date', 'albumstatus', 'albumdisambig', 'releasegroupdisambig', diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index b8e6108b4..55ee033d4 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -79,10 +79,10 @@ 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, + language=None, country=None, style=None, genre=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): + original_day=None, data_source=None, data_url=None, discogs_release_id=None, released_date=None): self.album = album self.album_id = album_id self.artist = artist @@ -103,6 +103,7 @@ class AlbumInfo(object): self.language = language self.country = country self.style = style + self.genre = genre self.albumstatus = albumstatus self.media = media self.albumdisambig = albumdisambig @@ -113,6 +114,8 @@ class AlbumInfo(object): self.original_day = original_day self.data_source = data_source self.data_url = data_url + self.discogs_release_id = discogs_release_id + self.released_date = released_date # Work around a bug in python-musicbrainz-ngs that causes some # strings to be bytes rather than Unicode. @@ -123,8 +126,8 @@ class AlbumInfo(object): """ for fld in ['album', 'artist', 'albumtype', 'label', 'artist_sort', 'catalognum', 'script', 'language', 'country', 'style', - 'albumstatus', 'albumdisambig', 'releasegroupdisambig', - 'artist_credit', 'media']: + 'genre', 'albumstatus', 'albumdisambig', 'releasegroupdisambig', + 'artist_credit', 'media', 'discogs_release_id', 'released_date']: value = getattr(self, fld) if isinstance(value, bytes): setattr(self, fld, value.decode(codec, 'ignore')) diff --git a/beets/library.py b/beets/library.py index c7fbe48cf..713ad53cd 100644 --- a/beets/library.py +++ b/beets/library.py @@ -437,6 +437,8 @@ class Item(LibModel): 'albumartist_credit': types.STRING, 'genre': types.STRING, 'style': types.STRING, + 'discogs_release_id': types.INTEGER, + 'released_date': types.STRING, 'lyricist': types.STRING, 'composer': types.STRING, 'composer_sort': types.STRING, @@ -917,6 +919,8 @@ class Album(LibModel): 'album': types.STRING, 'genre': types.STRING, 'style': types.STRING, + 'discogs_release_id': types.INTEGER, + 'released_date': types.STRING, 'year': types.PaddedInt(4), 'month': types.PaddedInt(2), 'day': types.PaddedInt(2), @@ -962,6 +966,9 @@ class Album(LibModel): 'albumartist_credit', 'album', 'genre', + 'style', + 'discogs_release_id', + 'released_date', 'year', 'month', 'day', diff --git a/beetsplug/beatport.py b/beetsplug/beatport.py index 0c25912b2..e85df87be 100644 --- a/beetsplug/beatport.py +++ b/beetsplug/beatport.py @@ -373,6 +373,7 @@ class BeatportPlugin(BeetsPlugin): return None release = self.client.get_release(match.group(2)) album = self._get_album_info(release) + print('ALBUM', album) return album def track_for_id(self, track_id): diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index f6197ddba..280bc659d 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -303,7 +303,10 @@ class DiscogsPlugin(BeetsPlugin): mediums = [t.medium for t in tracks] country = result.data.get('country') data_url = result.data.get('uri') - style = self.format_style(result.data.get('styles')) + style = self.format(result.data.get('styles')) + genre = self.format(result.data.get('genres')) + discogs_release_id = self.extract_release_id(result.data.get('uri')) + released_date = result.data.get('released') # Extract information for the optional AlbumInfo fields that are # contained on nested discogs fields. @@ -341,18 +344,21 @@ 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, style=style, + country=country, style=style, genre=genre, albumstatus=None, media=media, albumdisambig=None, artist_credit=None, original_year=original_year, original_month=None, original_day=None, data_source='Discogs', - data_url=data_url) + data_url=data_url, discogs_release_id=discogs_release_id, released_date=released_date) - def format_style(self, style): - if style is None: - self._log.debug('Style not Found') + def format(self, classification): + if classification is None: + self._log.debug('Classification not Found') else: - return self.config['separator'].as_str().join(sorted(style)) + return self.config['separator'].as_str().join(sorted(classification)) + + def extract_release_id(self, uri): + return uri.split("/")[-1] def get_artist(self, artists): """Returns an artist string (all artists) and an artist_id (the main From e9dd226b93bc59afdacfc3fb89fa8f9f4d9c9cc2 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 30 Jun 2019 12:06:38 +0200 Subject: [PATCH 02/11] fixing test --- test/test_discogs.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_discogs.py b/test/test_discogs.py index 0acf54e8a..693768916 100644 --- a/test/test_discogs.py +++ b/test/test_discogs.py @@ -48,6 +48,9 @@ class DGAlbumInfoTest(_common.TestCase): 'styles': [ 'STYLE1', 'STYLE2' ], + 'genres': [ + 'GENRE1', 'GENRE2' + ], 'labels': [{ 'name': 'LABEL NAME', 'catno': 'CATALOG NUMBER', From 0e2e2dfec33138557490db257d5230af5d87023e Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 30 Jun 2019 12:22:22 +0200 Subject: [PATCH 03/11] adding additional discogs attrributes --- test/test_discogs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_discogs.py b/test/test_discogs.py index 693768916..d97f172b9 100644 --- a/test/test_discogs.py +++ b/test/test_discogs.py @@ -35,6 +35,7 @@ class DGAlbumInfoTest(_common.TestCase): 'uri': 'ALBUM URI', 'title': 'ALBUM TITLE', 'year': '3001', + 'released': '2019-06-07', 'artists': [{ 'name': 'ARTIST NAME', 'id': 'ARTIST ID', From 8bf9d75f668dee13fed39fb08768656aace776fd Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 30 Jun 2019 12:50:36 +0200 Subject: [PATCH 04/11] fixing test --- test/test_discogs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_discogs.py b/test/test_discogs.py index d97f172b9..6b8fdb8d8 100644 --- a/test/test_discogs.py +++ b/test/test_discogs.py @@ -32,7 +32,7 @@ class DGAlbumInfoTest(_common.TestCase): those required for the tests on this class.""" data = { 'id': 'ALBUM ID', - 'uri': 'ALBUM URI', + 'uri': 'https://www.discogs.com/release/release/13633721', 'title': 'ALBUM TITLE', 'year': '3001', 'released': '2019-06-07', From 510276f653e4dbbc1e05c2369b08632a88d21103 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 30 Jun 2019 13:44:13 +0200 Subject: [PATCH 05/11] fixing test --- beets/autotag/hooks.py | 15 +++++++++------ beetsplug/discogs.py | 7 +++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index 55ee033d4..fa4e0d73f 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -79,10 +79,12 @@ 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, genre=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, discogs_release_id=None, released_date=None): + language=None, country=None, style=None, genre=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, + discogs_release_id=None, released_date=None): self.album = album self.album_id = album_id self.artist = artist @@ -126,8 +128,9 @@ class AlbumInfo(object): """ for fld in ['album', 'artist', 'albumtype', 'label', 'artist_sort', 'catalognum', 'script', 'language', 'country', 'style', - 'genre', 'albumstatus', 'albumdisambig', 'releasegroupdisambig', - 'artist_credit', 'media', 'discogs_release_id', 'released_date']: + 'genre', 'albumstatus', 'albumdisambig', + 'releasegroupdisambig', 'artist_credit', + 'media', 'discogs_release_id', 'released_date']: value = getattr(self, fld) if isinstance(value, bytes): setattr(self, fld, value.decode(codec, 'ignore')) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 280bc659d..2469b85e5 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -349,7 +349,9 @@ class DiscogsPlugin(BeetsPlugin): albumdisambig=None, artist_credit=None, original_year=original_year, original_month=None, original_day=None, data_source='Discogs', - data_url=data_url, discogs_release_id=discogs_release_id, released_date=released_date) + data_url=data_url, + discogs_release_id=discogs_release_id, + released_date=released_date) def format(self, classification): if classification is None: @@ -358,7 +360,8 @@ class DiscogsPlugin(BeetsPlugin): return self.config['separator'].as_str().join(sorted(classification)) def extract_release_id(self, uri): - return uri.split("/")[-1] + if uri: + return uri.split("/")[-1] def get_artist(self, artists): """Returns an artist string (all artists) and an artist_id (the main From e196c1dae6311dac44c8aece63ddaae4a8c5bdc8 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 30 Jun 2019 13:54:38 +0200 Subject: [PATCH 06/11] fixing test --- beetsplug/discogs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 2469b85e5..4daa82fbf 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -357,7 +357,8 @@ class DiscogsPlugin(BeetsPlugin): if classification is None: self._log.debug('Classification not Found') else: - return self.config['separator'].as_str().join(sorted(classification)) + return self.config['separator'].as_str()\ + .join(sorted(classification)) def extract_release_id(self, uri): if uri: From 6ae73546e522fedf68c35d29f69f6ebfe16a3c90 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 30 Jun 2019 14:09:31 +0200 Subject: [PATCH 07/11] Trigger From dd7e932a9a6b2eeaa4590c11d9c0e7ec381e5bc0 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 30 Jun 2019 14:34:13 +0200 Subject: [PATCH 08/11] removing print log --- beetsplug/beatport.py | 1 - 1 file changed, 1 deletion(-) diff --git a/beetsplug/beatport.py b/beetsplug/beatport.py index e85df87be..0c25912b2 100644 --- a/beetsplug/beatport.py +++ b/beetsplug/beatport.py @@ -373,7 +373,6 @@ class BeatportPlugin(BeetsPlugin): return None release = self.client.get_release(match.group(2)) album = self._get_album_info(release) - print('ALBUM', album) return album def track_for_id(self, track_id): From 0cd46dab770f8ae96e70760cec6393d175eaecbd Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 1 Jul 2019 21:04:35 +0200 Subject: [PATCH 09/11] fixing per review comments --- beets/autotag/__init__.py | 4 ++-- beets/autotag/hooks.py | 7 +++---- beets/library.py | 9 +++------ beetsplug/discogs.py | 16 ++++++++-------- test/test_discogs.py | 1 - 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index 5d116c7f2..b0bbbbf04 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -157,8 +157,8 @@ def apply_metadata(album_info, mapping): 'country', 'style', 'genre', - 'discogs_release_id', - 'released_date', + 'discogs_albumid', + '', 'albumstatus', 'albumdisambig', 'releasegroupdisambig', diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index fa4e0d73f..b946ff7c9 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -84,7 +84,7 @@ class AlbumInfo(object): releasegroupdisambig=None, artist_credit=None, original_year=None, original_month=None, original_day=None, data_source=None, data_url=None, - discogs_release_id=None, released_date=None): + discogs_albumid=None): self.album = album self.album_id = album_id self.artist = artist @@ -116,8 +116,7 @@ class AlbumInfo(object): self.original_day = original_day self.data_source = data_source self.data_url = data_url - self.discogs_release_id = discogs_release_id - self.released_date = released_date + self.discogs_albumid = discogs_albumid # Work around a bug in python-musicbrainz-ngs that causes some # strings to be bytes rather than Unicode. @@ -130,7 +129,7 @@ class AlbumInfo(object): 'catalognum', 'script', 'language', 'country', 'style', 'genre', 'albumstatus', 'albumdisambig', 'releasegroupdisambig', 'artist_credit', - 'media', 'discogs_release_id', 'released_date']: + 'media', 'discogs_albumid']: value = getattr(self, fld) if isinstance(value, bytes): setattr(self, fld, value.decode(codec, 'ignore')) diff --git a/beets/library.py b/beets/library.py index 713ad53cd..12850f933 100644 --- a/beets/library.py +++ b/beets/library.py @@ -437,8 +437,7 @@ class Item(LibModel): 'albumartist_credit': types.STRING, 'genre': types.STRING, 'style': types.STRING, - 'discogs_release_id': types.INTEGER, - 'released_date': types.STRING, + 'discogs_albumid': types.INTEGER, 'lyricist': types.STRING, 'composer': types.STRING, 'composer_sort': types.STRING, @@ -919,8 +918,7 @@ class Album(LibModel): 'album': types.STRING, 'genre': types.STRING, 'style': types.STRING, - 'discogs_release_id': types.INTEGER, - 'released_date': types.STRING, + 'discogs_albumid': types.INTEGER, 'year': types.PaddedInt(4), 'month': types.PaddedInt(2), 'day': types.PaddedInt(2), @@ -967,8 +965,7 @@ class Album(LibModel): 'album', 'genre', 'style', - 'discogs_release_id', - 'released_date', + 'discogs_albumid', 'year', 'month', 'day', diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 4daa82fbf..92a5773f5 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -305,8 +305,7 @@ class DiscogsPlugin(BeetsPlugin): data_url = result.data.get('uri') style = self.format(result.data.get('styles')) genre = self.format(result.data.get('genres')) - discogs_release_id = self.extract_release_id(result.data.get('uri')) - released_date = result.data.get('released') + discogs_albumid = self.extract_release_id(result.data.get('uri')) # Extract information for the optional AlbumInfo fields that are # contained on nested discogs fields. @@ -350,19 +349,20 @@ class DiscogsPlugin(BeetsPlugin): original_year=original_year, original_month=None, original_day=None, data_source='Discogs', data_url=data_url, - discogs_release_id=discogs_release_id, - released_date=released_date) + discogs_albumid=discogs_albumid) def format(self, classification): - if classification is None: - self._log.debug('Classification not Found') - else: - return self.config['separator'].as_str()\ + if classification: + return self.config['separator'].as_str() \ .join(sorted(classification)) + else: + return None def extract_release_id(self, uri): if uri: return uri.split("/")[-1] + else: + return None def get_artist(self, artists): """Returns an artist string (all artists) and an artist_id (the main diff --git a/test/test_discogs.py b/test/test_discogs.py index 6b8fdb8d8..61d9d5aa1 100644 --- a/test/test_discogs.py +++ b/test/test_discogs.py @@ -35,7 +35,6 @@ class DGAlbumInfoTest(_common.TestCase): 'uri': 'https://www.discogs.com/release/release/13633721', 'title': 'ALBUM TITLE', 'year': '3001', - 'released': '2019-06-07', 'artists': [{ 'name': 'ARTIST NAME', 'id': 'ARTIST ID', From ad67d708182a95f74c57372d2055135d8b5bcd38 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 1 Jul 2019 21:05:31 +0200 Subject: [PATCH 10/11] removing empty string --- beets/autotag/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index b0bbbbf04..2c8a2f984 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -158,7 +158,6 @@ def apply_metadata(album_info, mapping): 'style', 'genre', 'discogs_albumid', - '', 'albumstatus', 'albumdisambig', 'releasegroupdisambig', From 1b4124931b72365b147a56bb97d07aee9ff3279a Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 1 Jul 2019 21:17:19 +0200 Subject: [PATCH 11/11] Trigger