Merge pull request #3322 from thedevilisinthedetails/master

465 discogs: Fetch a few more metadata fields
This commit is contained in:
Adrian Sampson 2019-07-01 17:22:50 -04:00
commit e39341b282
5 changed files with 38 additions and 14 deletions

View file

@ -162,6 +162,8 @@ def apply_metadata(album_info, mapping):
'language',
'country',
'style',
'genre',
'discogs_albumid',
'albumstatus',
'albumdisambig',
'releasegroupdisambig',

View file

@ -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'))

View file

@ -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',

View file

@ -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

View file

@ -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',