From 878161bb4f4099526321cd21bc8a8848438ffb60 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Thu, 31 Dec 2015 11:31:32 -0800 Subject: [PATCH] acousticbrainz: Avoid re-parsing the JSON --- beetsplug/acousticbrainz.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/beetsplug/acousticbrainz.py b/beetsplug/acousticbrainz.py index 9c0c18260..acc08488b 100644 --- a/beetsplug/acousticbrainz.py +++ b/beetsplug/acousticbrainz.py @@ -59,22 +59,25 @@ def fetch_info(log, lib): # Parse the JSON response. try: - rs.json() + data = rs.json() except ValueError: log.debug('Invalid Response: {}', rs.text) - item.danceable = get_value(log, rs.json(), ["highlevel", - "danceability", - "all", - "danceable"]) - item.mood_happy = get_value(log, rs.json(), ["highlevel", - "mood_happy", - "all", - "happy"]) - item.mood_party = get_value(log, rs.json(), ["highlevel", - "mood_party", - "all", - "party"]) + item.danceable = get_value( + log, + data, + ["highlevel", "danceability", "all", "danceable"], + ) + item.mood_happy = get_value( + log, + data, + ["highlevel", "mood_happy", "all", "happy"], + ) + item.mood_party = get_value( + log, + data, + ["highlevel", "mood_party", "all", "party"], + ) item.write() item.store()