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

Added temporary debug logging

This commit is contained in:
Krateng 2019-08-22 21:35:58 +02:00
parent 564f276496
commit a5feec7234
2 changed files with 18 additions and 3 deletions

View File

@ -68,6 +68,7 @@ def handle(path,keys):
def scrobbletrack(artiststr,titlestr,timestamp): def scrobbletrack(artiststr,titlestr,timestamp):
try: try:
log("Incoming scrobble (compliant API): ARTISTS: " + artiststr + ", TRACK: " + titlestr,module="debug")
(artists,title) = cla.fullclean(artiststr,titlestr) (artists,title) = cla.fullclean(artiststr,titlestr)
database.createScrobble(artists,title,timestamp) database.createScrobble(artists,title,timestamp)
database.sync() database.sync()

View File

@ -77,7 +77,12 @@ def loadAPIkeys():
log("Authenticated Machines: " + ", ".join([m[1] for m in clients])) log("Authenticated Machines: " + ", ".join([m[1] for m in clients]))
def checkAPIkey(k): def checkAPIkey(k):
return (k in [k for [k,d] in clients]) #return (k in [k for [k,d] in clients])
for key, identifier in clients:
if key == k: return identifier
return False
def allAPIkeys(): def allAPIkeys():
return [k for [k,d] in clients] return [k for [k,d] in clients]
@ -612,13 +617,16 @@ def pseudo_post_scrobble(**keys):
artists = keys.get("artist") artists = keys.get("artist")
title = keys.get("title") title = keys.get("title")
apikey = keys.get("key") apikey = keys.get("key")
if not (checkAPIkey(apikey)): client = checkAPIkey(apikey)
if client == False: # empty string allowed!
response.status = 403 response.status = 403
return "" return ""
try: try:
time = int(keys.get("time")) time = int(keys.get("time"))
except: except:
time = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()) time = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())
log("Incoming scrobble (native API): Client " + client + ", ARTISTS: " + str(artists) + ", TRACK: " + title,module="debug")
(artists,title) = cla.fullclean(artists,title) (artists,title) = cla.fullclean(artists,title)
## this is necessary for localhost testing ## this is necessary for localhost testing
@ -629,6 +637,8 @@ def pseudo_post_scrobble(**keys):
if (time - lastsync) > 3600: if (time - lastsync) > 3600:
sync() sync()
return {"status":"success","track":trackdict} return {"status":"success","track":trackdict}
@dbserver.post("newscrobble") @dbserver.post("newscrobble")
@ -636,7 +646,8 @@ def post_scrobble(**keys):
artists = keys.get("artist") artists = keys.get("artist")
title = keys.get("title") title = keys.get("title")
apikey = keys.get("key") apikey = keys.get("key")
if not (checkAPIkey(apikey)): client = checkAPIkey(apikey)
if client == False: # empty string allowed!
response.status = 403 response.status = 403
return "" return ""
@ -644,6 +655,8 @@ def post_scrobble(**keys):
time = int(keys.get("time")) time = int(keys.get("time"))
except: except:
time = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()) time = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())
log("Incoming scrobble (native API): Client " + client + ", ARTISTS: " + str(artists) + ", TRACK: " + title,module="debug")
(artists,title) = cla.fullclean(artists,title) (artists,title) = cla.fullclean(artists,title)
## this is necessary for localhost testing ## this is necessary for localhost testing
@ -657,6 +670,7 @@ def post_scrobble(**keys):
#always sync, one filesystem access every three minutes shouldn't matter #always sync, one filesystem access every three minutes shouldn't matter
return {"status":"success","track":trackdict} return {"status":"success","track":trackdict}