diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 54b76c9..e8acca5 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -93,8 +93,10 @@ def incoming_scrobble(rawscrobble,fix=True,client=None,api=None,dbconn=None): log(f"Incoming scrobble [Client: {client} | API: {api}]: {rawscrobble}") scrobbledict = rawscrobble_to_scrobbledict(rawscrobble, fix, client) + albumupdate = (malojaconf["ALBUM_INFORMATION_TRUST"] == 'last') - sqldb.add_scrobble(scrobbledict,dbconn=dbconn) + + sqldb.add_scrobble(scrobbledict,update_album=albumupdate,dbconn=dbconn) proxy_scrobble_all(scrobbledict['track']['artists'],scrobbledict['track']['title'],scrobbledict['time']) dbcache.invalidate_caches(scrobbledict['time']) diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index 3ec27f2..4b33dbe 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -254,12 +254,12 @@ def album_db_to_dict(row,dbconn=None): ### DICT -> DB # These should return None when no data is in the dict so they can be used for update statements -def scrobble_dict_to_db(info,dbconn=None): +def scrobble_dict_to_db(info,update_album=False,dbconn=None): return { "timestamp":info.get('time'), "origin":info.get('origin'), "duration":info.get('duration'), - "track_id":get_track_id(info.get('track'),dbconn=dbconn), + "track_id":get_track_id(info.get('track'),update_album=update_album,dbconn=dbconn), "extra":json.dumps(info.get('extra')) if info.get('extra') else None, "rawscrobble":json.dumps(info.get('rawscrobble')) if info.get('rawscrobble') else None } @@ -291,17 +291,17 @@ def album_dict_to_db(info,dbconn=None): @connection_provider -def add_scrobble(scrobbledict,dbconn=None): - add_scrobbles([scrobbledict],dbconn=dbconn) +def add_scrobble(scrobbledict,update_album=False,dbconn=None): + add_scrobbles([scrobbledict],update_album=update_album,dbconn=dbconn) @connection_provider -def add_scrobbles(scrobbleslist,dbconn=None): +def add_scrobbles(scrobbleslist,update_album=False,dbconn=None): with SCROBBLE_LOCK: ops = [ DB['scrobbles'].insert().values( - **scrobble_dict_to_db(s,dbconn=dbconn) + **scrobble_dict_to_db(s,update_album=update_album,dbconn=dbconn) ) for s in scrobbleslist ] diff --git a/maloja/pkg_global/conf.py b/maloja/pkg_global/conf.py index ea6a8c0..f11d569 100644 --- a/maloja/pkg_global/conf.py +++ b/maloja/pkg_global/conf.py @@ -177,6 +177,7 @@ malojaconfig = Configuration( }, "Database":{ + "album_information_trust":(tp.Choice({'first':"First",'last':"Last"}),"Album Information Authority","first", "Whether to trust the first album information that is sent with a track or update every time a different album is sent"), "invalid_artists":(tp.Set(tp.String()), "Invalid Artists", ["[Unknown Artist]","Unknown Artist","Spotify"], "Artists that should be discarded immediately"), "remove_from_title":(tp.Set(tp.String()), "Remove from Title", ["(Original Mix)","(Radio Edit)","(Album Version)","(Explicit Version)","(Bonus Track)"], "Phrases that should be removed from song titles"), "delimiters_feat":(tp.Set(tp.String()), "Featuring Delimiters", ["ft.","ft","feat.","feat","featuring"], "Delimiters used for extra artists, even when in the title field"),