ABrainz: Used existing initial_key variable

This commit is contained in:
Ohm Patel 2016-01-02 14:55:34 -06:00
parent 4184f9dd13
commit 1bb55c5c13
3 changed files with 8 additions and 15 deletions

View file

@ -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):

View file

@ -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,

View file

@ -22,8 +22,7 @@ these fields:
* ``danceable``
* ``gender``
* ``genre_rosamerica``
* ``key_key``
* ``key_scale``
* ``initial_key``
* ``key_strength``
* ``mood_acoustic``
* ``mood_aggressive``