Skip to content

Commit

Permalink
Merge pull request #3238 from rain0r/2790-acousticbrainz
Browse files Browse the repository at this point in the history
Fix for #2790 - acousticbrainz: Really small float values are stored as strings
  • Loading branch information
sampsyo committed Apr 30, 2019
2 parents fc084ae + 62c1d37 commit b6ac986
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
7 changes: 5 additions & 2 deletions beets/dbcore/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,17 @@ def __init__(self, primary=True):


class Float(Type):
"""A basic floating-point type.
"""A basic floating-point type. Supports padding.
"""
sql = u'REAL'
query = query.NumericQuery
model_type = float

def __init__(self, digits=1):
self.digits = digits

def format(self, value):
return u'{0:.1f}'.format(value or 0.0)
return u'{0:.{1}f}'.format(value or 0, self.digits)


class NullFloat(Float):
Expand Down
27 changes: 26 additions & 1 deletion beetsplug/acousticbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
"""
from __future__ import division, absolute_import, print_function

from collections import defaultdict

import requests

from collections import defaultdict
from beets import plugins, ui
from beets.dbcore import types

ACOUSTIC_BASE = "https://acousticbrainz.org/"
LEVELS = ["/low-level", "/high-level"]
Expand Down Expand Up @@ -104,6 +106,29 @@


class AcousticPlugin(plugins.BeetsPlugin):
item_types = {
'average_loudness': types.Float(6),
'chords_changes_rate': types.Float(6),
'chords_key': types.STRING,
'chords_number_rate': types.Float(6),
'chords_scale': types.STRING,
'danceable': types.Float(6),
'gender': types.STRING,
'genre_rosamerica': types.STRING,
'initial_key': types.STRING,
'key_strength': types.Float(6),
'mood_acoustic': types.Float(6),
'mood_aggressive': types.Float(6),
'mood_electronic': types.Float(6),
'mood_happy': types.Float(6),
'mood_party': types.Float(6),
'mood_relaxed': types.Float(6),
'mood_sad': types.Float(6),
'rhythm': types.Float(6),
'tonal': types.Float(6),
'voice_instrumental': types.STRING,
}

def __init__(self):
super(AcousticPlugin, self).__init__()

Expand Down

0 comments on commit b6ac986

Please sign in to comment.