From 1bb55c5c13e1994ad77c0ffaf218b04887d58d35 Mon Sep 17 00:00:00 2001 From: Ohm Patel Date: Sat, 2 Jan 2016 14:55:34 -0600 Subject: [PATCH] ABrainz: Used existing initial_key variable --- beets/library.py | 1 + beetsplug/acousticbrainz.py | 19 ++++++------------- docs/plugins/acousticbrainz.rst | 3 +-- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/beets/library.py b/beets/library.py index 474279b30..b42dd2c47 100644 --- a/beets/library.py +++ b/beets/library.py @@ -186,6 +186,7 @@ class MusicalKey(types.String): for flat, sharp in self.ENHARMONIC.items(): key = re.sub(flat, sharp, key) key = re.sub(r'[\W\s]+minor', 'm', key) + key = re.sub(r'[\W\s]+major', '', key) return key.capitalize() def normalize(self, key): diff --git a/beetsplug/acousticbrainz.py b/beetsplug/acousticbrainz.py index 3d03feaae..79bce75c3 100644 --- a/beetsplug/acousticbrainz.py +++ b/beetsplug/acousticbrainz.py @@ -63,8 +63,7 @@ def fetch_info(log, items): # Fetch the data from the AB API. high_url = generate_url(item.mb_trackid, "/high-level") low_url = generate_url(item.mb_trackid, "/low-level") - log.debug('fetching URL: {}', high_url) - log.debug('fetching URL: {}', low_url) + log.debug('fetching URLs: {} and {}', high_url, low_url) try: high = requests.get(high_url) low = requests.get(low_url) @@ -81,11 +80,11 @@ def fetch_info(log, items): try: high_data = high.json() except ValueError: - log.debug('Invalid Response: {}', high.text) + log.debug('Invalid Response from high-level: {}', high.text) try: low_data = low.json() except ValueError: - log.debug('Invalid Response: {}', low.text) + log.debug('Invalid Response from low-level: {}', low.text) # Get each field and assign it on the item. item.danceable = get_value( @@ -178,15 +177,9 @@ def fetch_info(log, items): low_data, ["tonal", "chords_scale"], ) - item.key_key = get_value( - log, - low_data, - ["tonal", "key_key"], - ) - item.key_scale = get_value( - log, - low_data, - ["tonal", "key_scale"], + item.initial_key = '{} {}'.format( + get_value(log, low_data, ["tonal", "key_key"]), + get_value(log, low_data, ["tonal", "key_scale"]) ) item.key_strength = get_value( log, diff --git a/docs/plugins/acousticbrainz.rst b/docs/plugins/acousticbrainz.rst index 24232437a..d782d3110 100644 --- a/docs/plugins/acousticbrainz.rst +++ b/docs/plugins/acousticbrainz.rst @@ -22,8 +22,7 @@ these fields: * ``danceable`` * ``gender`` * ``genre_rosamerica`` -* ``key_key`` -* ``key_scale`` +* ``initial_key`` * ``key_strength`` * ``mood_acoustic`` * ``mood_aggressive``