diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index df0d94abb..07d1feffa 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -162,6 +162,8 @@ def apply_metadata(album_info, mapping): 'language', 'country', 'style', + 'genre', + 'discogs_albumid', 'albumstatus', 'albumdisambig', 'releasegroupdisambig', diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index 27db4fad7..686423360 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, 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): + 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_albumid=None): self.album = album self.album_id = album_id self.artist = artist @@ -103,6 +105,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 +116,7 @@ class AlbumInfo(object): self.original_day = original_day self.data_source = data_source self.data_url = data_url + self.discogs_albumid = discogs_albumid # Work around a bug in python-musicbrainz-ngs that causes some # strings to be bytes rather than Unicode. @@ -123,8 +127,9 @@ 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_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 0555b9baf..4c7fb894c 100644 --- a/beets/library.py +++ b/beets/library.py @@ -449,6 +449,7 @@ class Item(LibModel): 'albumartist_credit': types.STRING, 'genre': types.STRING, 'style': types.STRING, + 'discogs_albumid': types.INTEGER, 'lyricist': types.STRING, 'composer': types.STRING, 'composer_sort': types.STRING, @@ -932,6 +933,7 @@ class Album(LibModel): 'album': types.STRING, 'genre': types.STRING, 'style': types.STRING, + 'discogs_albumid': types.INTEGER, 'year': types.PaddedInt(4), 'month': types.PaddedInt(2), 'day': types.PaddedInt(2), @@ -977,6 +979,8 @@ class Album(LibModel): 'albumartist_credit', 'album', 'genre', + 'style', + 'discogs_albumid', 'year', 'month', 'day', diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index e97772af6..3ba68e2ce 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -303,7 +303,9 @@ 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_albumid = self.extract_release_id(result.data.get('uri')) # Extract information for the optional AlbumInfo fields that are # contained on nested discogs fields. @@ -341,18 +343,26 @@ 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_albumid=discogs_albumid) - def format_style(self, style): - if style is None: - self._log.debug('Style not Found') + def format(self, classification): + if classification: + return self.config['separator'].as_str() \ + .join(sorted(classification)) else: - return self.config['separator'].as_str().join(sorted(style)) + 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 0acf54e8a..61d9d5aa1 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', 'artists': [{ @@ -48,6 +48,9 @@ class DGAlbumInfoTest(_common.TestCase): 'styles': [ 'STYLE1', 'STYLE2' ], + 'genres': [ + 'GENRE1', 'GENRE2' + ], 'labels': [{ 'name': 'LABEL NAME', 'catno': 'CATALOG NUMBER',