Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2579 Adding styles to discogs plugin #3251

Merged
merged 16 commits into from
Jun 10, 2019
1 change: 1 addition & 0 deletions beets/autotag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,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 @@ -436,6 +436,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 @@ -915,6 +916,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
13 changes: 12 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,21 @@ 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')
elif not style:
return style
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to return [], i.e., an empty list, instead of a string. I think it should be fine to remove this entire elif case: if the string is empty, then 'something'.join(sorted([])) will return '', which is probably what we want.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D Think there was some confusion. When i was checking len == 0 it should have been len== 1. If there is only one style tag in the response then I want to just return that style tag as is with no formatting. So I guess I just needed to chage len == 0 to len == 1. Hope this clarifies what I am trying to achieve. If this makes sense I will make the change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does! But I still don't think this elif case is necessary for that—a single style in the list will still "do nothing" when joined. For example:

>>> ', '.join(['foo'])
'foo'

…so the one-element list case is also handled by the general case.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 fixed

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
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = py27-test, py37-test, py38-test, py27-flake8, docs
envlist = py27-test, py37-test, py27-flake8, docs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is showing up in the diff? py38-test is disabled by default on master.


# The exhaustive list of environments is:
# envlist = py{27,34,35}-{test,cov}, py{27,34,35}-flake8, docs
Expand Down