Skip to content

Commit

Permalink
Merge pull request #3322 from thedevilisinthedetails/master
Browse files Browse the repository at this point in the history
465 discogs: Fetch a few more metadata fields
  • Loading branch information
sampsyo committed Jul 1, 2019
2 parents 23c9f87 + 1b41249 commit e39341b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
2 changes: 2 additions & 0 deletions beets/autotag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ def apply_metadata(album_info, mapping):
'language',
'country',
'style',
'genre',
'discogs_albumid',
'albumstatus',
'albumdisambig',
'releasegroupdisambig',
Expand Down
17 changes: 11 additions & 6 deletions beets/autotag/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ def __init__(self, album, album_id, artist, artist_id, tracks, asin=None,
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
Expand All @@ -103,6 +105,7 @@ def __init__(self, album, album_id, artist, artist_id, tracks, asin=None,
self.language = language
self.country = country
self.style = style
self.genre = genre
self.albumstatus = albumstatus
self.media = media
self.albumdisambig = albumdisambig
Expand All @@ -113,6 +116,7 @@ def __init__(self, album, album_id, artist, artist_id, tracks, asin=None,
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.
Expand All @@ -123,8 +127,9 @@ def decode(self, codec='utf-8'):
"""
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'))
Expand Down
4 changes: 4 additions & 0 deletions beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -977,6 +979,8 @@ class Album(LibModel):
'albumartist_credit',
'album',
'genre',
'style',
'discogs_albumid',
'year',
'month',
'day',
Expand Down
24 changes: 17 additions & 7 deletions beetsplug/discogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ def get_album_info(self, result):
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.
Expand Down Expand Up @@ -341,18 +343,26 @@ def get_album_info(self, result):
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
Expand Down
5 changes: 4 additions & 1 deletion test/test_discogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _make_release(self, tracks=None):
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': [{
Expand All @@ -48,6 +48,9 @@ def _make_release(self, tracks=None):
'styles': [
'STYLE1', 'STYLE2'
],
'genres': [
'GENRE1', 'GENRE2'
],
'labels': [{
'name': 'LABEL NAME',
'catno': 'CATALOG NUMBER',
Expand Down

0 comments on commit e39341b

Please sign in to comment.