Skip to content

Commit

Permalink
Merge pull request #3251 from thedevilisinthedetails/master
Browse files Browse the repository at this point in the history
#2579 Adding styles to discogs plugin
  • Loading branch information
sampsyo committed Jun 10, 2019
2 parents 6a96167 + 34c2852 commit ed30a7a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions beets/autotag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def apply_metadata(album_info, mapping):
'script',
'language',
'country',
'style',
'albumstatus',
'albumdisambig',
'releasegroupdisambig',
Expand Down
7 changes: 4 additions & 3 deletions beets/autotag/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ 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, 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
Expand All @@ -102,6 +102,7 @@ def __init__(self, album, album_id, artist, artist_id, tracks, asin=None,
self.script = script
self.language = language
self.country = country
self.style = style
self.albumstatus = albumstatus
self.media = media
self.albumdisambig = albumdisambig
Expand All @@ -121,7 +122,7 @@ def decode(self, codec='utf-8'):
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)
Expand Down
2 changes: 2 additions & 0 deletions beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,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,
Expand Down Expand Up @@ -930,6 +931,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),
Expand Down
11 changes: 10 additions & 1 deletion beetsplug/discogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(self):
'tokenfile': 'discogs_token.json',
'source_weight': 0.5,
'user_token': '',
'separator': u', '
})
self.config['apikey'].redact = True
self.config['apisecret'].redact = True
Expand Down Expand Up @@ -302,6 +303,7 @@ 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'))

# Extract information for the optional AlbumInfo fields that are
# contained on nested discogs fields.
Expand Down Expand Up @@ -339,12 +341,19 @@ 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, 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',
data_url=data_url)

def format_style(self, style):
if style is None:
self._log.debug('Style not Found')
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.
Expand Down
3 changes: 3 additions & 0 deletions test/test_discogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def _make_release(self, tracks=None):
'name': 'FORMAT',
'qty': 1
}],
'styles': [
'STYLE1', 'STYLE2'
],
'labels': [{
'name': 'LABEL NAME',
'catno': 'CATALOG NUMBER',
Expand Down

0 comments on commit ed30a7a

Please sign in to comment.