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

Fixed convoluted old scrobbling functionality

This commit is contained in:
krateng 2022-02-13 06:15:29 +01:00
parent 034f8b32c7
commit a64d3610d3
4 changed files with 20 additions and 26 deletions

View File

@ -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()

View File

@ -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}

View File

@ -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']

View File

@ -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 + "!";