From 848f009774f6d9dfb62cc2b5c4abd440182fe4a8 Mon Sep 17 00:00:00 2001 From: krateng Date: Thu, 7 Apr 2022 20:00:26 +0200 Subject: [PATCH] Distinction between external and internal scrobble info --- maloja/database/sqldb.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index 39957ed..c564b3c 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -141,11 +141,11 @@ def connection_provider(func): # }, # "duration":int, # "origin":string, -# "extra":{string-keyed mapping for all flags with the scrobble} +# "extra":{string-keyed mapping for all flags with the scrobble}, +# "rawscrobble":{string-keyed mapping of the original scrobble received} # } # -# The dict sent to the DB can have one extra field 'rawscrobble', but this isn't -# returned on read +# The last two fields are not returned under normal circumstances @@ -157,16 +157,22 @@ def connection_provider(func): ### DB -> DICT -def scrobbles_db_to_dict(rows): +def scrobbles_db_to_dict(rows,include_internal=False): tracks = get_tracks_map(set(row.track_id for row in rows)) return [ { - "time":row.timestamp, - "track":tracks[row.track_id], - "duration":row.duration, - "origin":row.origin, - "extra":json.loads(row.extra or '{}') + **{ + "time":row.timestamp, + "track":tracks[row.track_id], + "duration":row.duration, + "origin":row.origin, + }, + **({ + "extra":json.loads(row.extra or '{}'), + "rawscrobble":json.loads(row.rawscrobble or '{}') + } if include_internal else {}) } + for row in rows ] @@ -209,7 +215,7 @@ def scrobble_dict_to_db(info): "duration":info['duration'], "track_id":get_track_id(info['track']), "extra":json.dumps(info.get('extra',{})), - "rawscrobble":json.dumps(info.get('rawscrobble')) + "rawscrobble":json.dumps(info.get('rawscrobble',{})) } def track_dict_to_db(info):