diff --git a/beetsplug/acousticbrainz.py b/beetsplug/acousticbrainz.py index bbbd098c7..3a6db7d4e 100644 --- a/beetsplug/acousticbrainz.py +++ b/beetsplug/acousticbrainz.py @@ -22,6 +22,7 @@ from collections import defaultdict import requests from beets import plugins, ui +from beets.dbcore import types ACOUSTIC_BASE = "https://acousticbrainz.org/" LEVELS = ["/low-level", "/high-level"] @@ -102,13 +103,32 @@ ABSCHEME = { } } -FLOAT_FIELDS = ['danceable', 'mood_acoustic', 'mood_aggressive', - 'mood_electronic', 'mood_happy', 'mood_party', 'mood_relaxed', - 'mood_sad', 'tonal', 'average_loudness', 'chords_changes_rate', - 'chords_number_rate', 'key_strength'] class AcousticPlugin(plugins.BeetsPlugin): + item_types = { + 'average_loudness': types.FLOAT, + 'chords_changes_rate': types.FLOAT, + 'chords_key': types.STRING, + 'chords_number_rate': types.FLOAT, + 'chords_scale': types.STRING, + 'danceable': types.FLOAT, + 'gender': types.STRING, + 'genre_rosamerica': types.STRING, + 'initial_key': types.STRING, + 'key_strength': types.FLOAT, + 'mood_acoustic': types.FLOAT, + 'mood_aggressive': types.FLOAT, + 'mood_electronic': types.FLOAT, + 'mood_happy': types.FLOAT, + 'mood_party': types.FLOAT, + 'mood_relaxed': types.FLOAT, + 'mood_sad': types.FLOAT, + 'rhythm': types.FLOAT, + 'tonal': types.FLOAT, + 'voice_instrumental': types.STRING, + } + def __init__(self): super(AcousticPlugin, self).__init__() @@ -156,7 +176,7 @@ class AcousticPlugin(plugins.BeetsPlugin): return {} if res.status_code == 404: - self._log.info(u'recording ID {} not found', mbid) + self._log.info(u'recording ID \'{}\' not found', mbid) return {} try: @@ -179,28 +199,27 @@ class AcousticPlugin(plugins.BeetsPlugin): if not force: mood_str = item.get('mood_acoustic', u'') if mood_str: - self._log.info(u'data already present for: {}', item) + self._log.info(u'data already present for: \'{}\'', item) continue # We can only fetch data for tracks with MBIDs. if not item.mb_trackid: continue - self._log.info(u'getting data for: {}', item) + self._log.info(u'getting data for: \'{}\'', item) data = self._get_data(item.mb_trackid) if data: for attr, val in self._map_data_to_scheme(data, ABSCHEME): if not tags or attr in tags: - if attr in FLOAT_FIELDS: - val = '%f' % val - self._log.debug(u'attribute {} of {} set to {}', - attr, - item, - val) + self._log.debug( + u'attribute \'{}\' of \'{}\' set to \'{}\'', + attr, + item, + val) setattr(item, attr, val) else: - self._log.debug(u'skipping attribute {} of {}' - u' (value {}) due to config', + self._log.debug(u'skipping attribute \'{}\' of \'{}\'' + u' (value \'{}\') due to config', attr, item, val)