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

Added setting for album information update

This commit is contained in:
krateng 2023-03-28 16:14:29 +02:00
parent 3a4f145f41
commit 657bb7e6d7
3 changed files with 10 additions and 7 deletions

View File

@ -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}") log(f"Incoming scrobble [Client: {client} | API: {api}]: {rawscrobble}")
scrobbledict = rawscrobble_to_scrobbledict(rawscrobble, fix, client) 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']) proxy_scrobble_all(scrobbledict['track']['artists'],scrobbledict['track']['title'],scrobbledict['time'])
dbcache.invalidate_caches(scrobbledict['time']) dbcache.invalidate_caches(scrobbledict['time'])

View File

@ -254,12 +254,12 @@ def album_db_to_dict(row,dbconn=None):
### DICT -> DB ### DICT -> DB
# These should return None when no data is in the dict so they can be used for update statements # 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 { return {
"timestamp":info.get('time'), "timestamp":info.get('time'),
"origin":info.get('origin'), "origin":info.get('origin'),
"duration":info.get('duration'), "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, "extra":json.dumps(info.get('extra')) if info.get('extra') else None,
"rawscrobble":json.dumps(info.get('rawscrobble')) if info.get('rawscrobble') 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 @connection_provider
def add_scrobble(scrobbledict,dbconn=None): def add_scrobble(scrobbledict,update_album=False,dbconn=None):
add_scrobbles([scrobbledict],dbconn=dbconn) add_scrobbles([scrobbledict],update_album=update_album,dbconn=dbconn)
@connection_provider @connection_provider
def add_scrobbles(scrobbleslist,dbconn=None): def add_scrobbles(scrobbleslist,update_album=False,dbconn=None):
with SCROBBLE_LOCK: with SCROBBLE_LOCK:
ops = [ ops = [
DB['scrobbles'].insert().values( 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 ) for s in scrobbleslist
] ]

View File

@ -177,6 +177,7 @@ malojaconfig = Configuration(
}, },
"Database":{ "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"), "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"), "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"), "delimiters_feat":(tp.Set(tp.String()), "Featuring Delimiters", ["ft.","ft","feat.","feat","featuring"], "Delimiters used for extra artists, even when in the title field"),