1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Distinction between external and internal scrobble info

This commit is contained in:
krateng 2022-04-07 20:00:26 +02:00
parent c9fa9956bb
commit 848f009774

View File

@ -141,11 +141,11 @@ def connection_provider(func):
# }, # },
# "duration":int, # "duration":int,
# "origin":string, # "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 # The last two fields are not returned under normal circumstances
# returned on read
@ -157,16 +157,22 @@ def connection_provider(func):
### DB -> DICT ### 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)) tracks = get_tracks_map(set(row.track_id for row in rows))
return [ return [
{ {
**{
"time":row.timestamp, "time":row.timestamp,
"track":tracks[row.track_id], "track":tracks[row.track_id],
"duration":row.duration, "duration":row.duration,
"origin":row.origin, "origin":row.origin,
"extra":json.loads(row.extra or '{}') },
**({
"extra":json.loads(row.extra or '{}'),
"rawscrobble":json.loads(row.rawscrobble or '{}')
} if include_internal else {})
} }
for row in rows for row in rows
] ]
@ -209,7 +215,7 @@ def scrobble_dict_to_db(info):
"duration":info['duration'], "duration":info['duration'],
"track_id":get_track_id(info['track']), "track_id":get_track_id(info['track']),
"extra":json.dumps(info.get('extra',{})), "extra":json.dumps(info.get('extra',{})),
"rawscrobble":json.dumps(info.get('rawscrobble')) "rawscrobble":json.dumps(info.get('rawscrobble',{}))
} }
def track_dict_to_db(info): def track_dict_to_db(info):