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

More normalizing

This commit is contained in:
krateng 2022-04-08 04:52:59 +02:00
parent e9d8303763
commit 037f195803
2 changed files with 30 additions and 30 deletions

View File

@ -113,7 +113,7 @@ def incoming_scrobble(rawscrobble,fix=True,client=None,api=None,dbconn=None):
"length":scrobbleinfo.get('track_length') "length":scrobbleinfo.get('track_length')
}, },
"duration":scrobbleinfo.get('scrobble_duration'), "duration":scrobbleinfo.get('scrobble_duration'),
"origin":f"client: {client}" if client else "generic", "origin":f"client:{client}" if client else "generic",
"extra":{ "extra":{
k:scrobbleinfo[k] for k in scrobbleinfo if k not in k:scrobbleinfo[k] for k in scrobbleinfo if k not in
['scrobble_time','track_artists','track_title','track_length','scrobble_duration','album_name','album_artists'] ['scrobble_time','track_artists','track_title','track_length','scrobble_duration','album_name','album_artists']

View File

@ -64,27 +64,27 @@ def import_scrobbles(inputf):
if status in ['CONFIDENT_IMPORT','UNCERTAIN_IMPORT']: if status in ['CONFIDENT_IMPORT','UNCERTAIN_IMPORT']:
# prevent duplicate timestamps # prevent duplicate timestamps
while scrobble['timestamp'] in timestamps: while scrobble['scrobble_time'] in timestamps:
scrobble['timestamp'] += 1 scrobble['scrobble_time'] += 1
timestamps.add(scrobble['timestamp']) timestamps.add(scrobble['scrobble_time'])
# clean up # clean up
(scrobble['artists'],scrobble['title']) = c.fullclean(scrobble['artists'],scrobble['title']) (scrobble['track_artists'],scrobble['track_title']) = c.fullclean(scrobble['track_artists'],scrobble['track_title'])
# extra info # extra info
extrainfo = {} extrainfo = {}
if scrobble.get('album'): extrainfo['album_name'] = scrobble['album'] if scrobble.get('album_name'): extrainfo['album_name'] = scrobble['album_name']
# saving this in the scrobble instead of the track because for now it's not meant # saving this in the scrobble instead of the track because for now it's not meant
# to be authorative information, just payload of the scrobble # to be authorative information, just payload of the scrobble
scrobblebuffer.append({ scrobblebuffer.append({
"time":scrobble['timestamp'], "time":scrobble['scrobble_time'],
"track":{ "track":{
"artists":scrobble['artists'], "artists":scrobble['track_artists'],
"title":scrobble['title'], "title":scrobble['track_title'],
"length":None "length":None
}, },
"duration":scrobble['duration'], "duration":scrobble['scrobble_duration'],
"origin":"import:" + typeid, "origin":"import:" + typeid,
"extra":extrainfo "extra":extrainfo
}) })
@ -145,11 +145,11 @@ def parse_spotify_lite(inputf):
continue continue
yield ("CONFIDENT_IMPORT",{ yield ("CONFIDENT_IMPORT",{
'title':title, 'track_title':title,
'artists': artist, 'track_artists': artist,
'timestamp': timestamp, 'scrobble_time': timestamp,
'duration':played, 'scrobble_duration':played,
'album': None 'album_name': None
},'') },'')
except Exception as e: except Exception as e:
yield ('FAIL',None,f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})") yield ('FAIL',None,f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})")
@ -249,11 +249,11 @@ def parse_spotify_full(inputf):
yield (status,{ yield (status,{
'title':title, 'track_title':title,
'artists': artist, 'track_artists': artist,
'album': album, 'album_name': album,
'timestamp': timestamp, 'scrobble_time': timestamp,
'duration':played 'scrobble_duration':played
},msg) },msg)
except Exception as e: except Exception as e:
yield ('FAIL',None,f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})") yield ('FAIL',None,f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})")
@ -275,14 +275,14 @@ def parse_lastfm(inputf):
try: try:
yield ('CONFIDENT_IMPORT',{ yield ('CONFIDENT_IMPORT',{
'title': title, 'track_title': title,
'artists': artist, 'track_artists': artist,
'album': album, 'album_name': album,
'timestamp': int(datetime.datetime.strptime( 'scrobble_time': int(datetime.datetime.strptime(
time + '+0000', time + '+0000',
"%d %b %Y %H:%M%z" "%d %b %Y %H:%M%z"
).timestamp()), ).timestamp()),
'duration':None 'scrobble_duration':None
},'') },'')
except Exception as e: except Exception as e:
yield ('FAIL',None,f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})") yield ('FAIL',None,f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})")
@ -299,11 +299,11 @@ def parse_maloja(inputf):
for s in scrobbles: for s in scrobbles:
try: try:
yield ('CONFIDENT_IMPORT',{ yield ('CONFIDENT_IMPORT',{
'title': s['track']['title'], 'track_title': s['track']['title'],
'artists': s['track']['artists'], 'track_artists': s['track']['artists'],
'album': s['track'].get('album',{}).get('name',''), 'album_name': s['track'].get('album',{}).get('name',''),
'timestamp': s['time'], 'scrobble_time': s['time'],
'duration': s['duration'] 'scrobble_duration': s['duration']
},'') },'')
except Exception as e: except Exception as e:
yield ('FAIL',None,f"{s} could not be parsed. Scrobble not imported. ({repr(e)})") yield ('FAIL',None,f"{s} could not be parsed. Scrobble not imported. ({repr(e)})")