diff --git a/maloja/apis/_base.py b/maloja/apis/_base.py index 9a365d9..e1d7d36 100644 --- a/maloja/apis/_base.py +++ b/maloja/apis/_base.py @@ -95,7 +95,6 @@ class APIHandler: if time is None: time = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()) try: (artists,title) = cla.fullclean(artiststr,titlestr) - database.createScrobble(artists,title,time) - database.sync() + database.incoming_scrobble(artists,title,time) except: raise ScrobblingException() diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index c6934f1..b6a5db5 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -64,11 +64,6 @@ def waitfordb(func): -MEDALS_ARTISTS = {} #literally only changes once per year, no need to calculate that on the fly -MEDALS_TRACKS = {} -WEEKLY_TOPTRACKS = {} -WEEKLY_TOPARTISTS = {} - ISSUES = {} cla = CleanerAgent() @@ -77,10 +72,19 @@ coa = CollectorAgent() -def createScrobble(artists,title,time,album=None,duration=None,volatile=False): +def incoming_scrobble(artists,title,album=None,albumartists=None,duration=None,time=None,fix=True): + if time is None: + time = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()) + + log("Incoming scrobble (): ARTISTS: " + str(artists) + ", TRACK: " + title,module="debug") + if fix: + (artists,title) = cla.fullclean(artists,title) if len(artists) == 0 or title == "": - return {} + return {"status":"failure"} + + if albumartists is None: + albumartists = artists scrobbledict = { "time":time, @@ -89,7 +93,7 @@ def createScrobble(artists,title,time,album=None,duration=None,volatile=False): "title":title, "album":{ "name":album, - "artists":None + "artists":albumartists }, "length":None }, @@ -97,9 +101,11 @@ def createScrobble(artists,title,time,album=None,duration=None,volatile=False): "origin":"generic" } - add_scrobble(scrobbledict) + sqldb.add_scrobble(scrobbledict) proxy_scrobble_all(artists,title,time) - return scrobbledict + + return {"status":"success","scrobble":scrobbledict} + @@ -291,18 +297,7 @@ def track_info(track): -def incoming_scrobble(artists,title,album=None,duration=None,time=None,fix=True): - if time is None: - time = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()) - log("Incoming scrobble (): ARTISTS: " + str(artists) + ", TRACK: " + title,module="debug") - if fix: - (artists,title) = cla.fullclean(artists,title) - trackdict = createScrobble(artists,title,time,album,duration) - - sync() - - return {"status":"success","track":trackdict} diff --git a/maloja/thirdparty/__init__.py b/maloja/thirdparty/__init__.py index 68e221c..c065c0b 100644 --- a/maloja/thirdparty/__init__.py +++ b/maloja/thirdparty/__init__.py @@ -154,7 +154,7 @@ class ImportInterface(GenericInterface,abstract=True): def import_scrobbles(self): for scrobble in self.get_remote_scrobbles(): - database.createScrobble( + database.incoming_scrobble( artists=scrobble['artists'], title=scrobble['title'], time=scrobble['time'] diff --git a/maloja/web/static/js/manualscrobble.js b/maloja/web/static/js/manualscrobble.js index 4816632..30c3e9f 100644 --- a/maloja/web/static/js/manualscrobble.js +++ b/maloja/web/static/js/manualscrobble.js @@ -83,8 +83,8 @@ function scrobble(artists,title) { function scrobbledone(req) { result = req.response; - txt = result["track"]["title"] + " by " + result["track"]["artists"][0]; - if (result["track"]["artists"].length > 1) { + txt = result["scrobble"]["track"]["title"] + " by " + result["scrobble"]["track"]["artists"][0]; + if (result["scrobble"]["track"]["artists"].length > 1) { txt += " et al."; } document.getElementById("notification").innerHTML = "Scrobbled " + txt + "!";