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

Fixed batch scrobbling with Listenbrainz API

This commit is contained in:
Johannes Krattenmacher
2020-09-07 20:26:23 +02:00
parent 160e393a00
commit b4d224fb66
2 changed files with 80 additions and 29 deletions

View File

@@ -40,26 +40,28 @@ class Listenbrainz(APIHandler):
try:
listentype = keys["listen_type"]
payload = keys["payload"]
if listentype in ["single","import"]:
for listen in payload:
except:
raise MalformedJSONException()
if listentype == "playing_now":
return 200,{"status":"ok"}
elif listentype in ["single","import"]:
for listen in payload:
try:
metadata = listen["track_metadata"]
artiststr, titlestr = metadata["artist_name"], metadata["track_name"]
#(artists,title) = cla.fullclean(artiststr,titlestr)
try:
timestamp = int(listen["listened_at"])
except:
timestamp = None
elif listentype == "playing_now":
pass
except:
raise MalformedJSONException()
except:
raise MalformedJSONException()
self.scrobble(artiststr,titlestr,timestamp)
if listentype == "playing_now": return 200,{"status":"ok"}
else:
self.scrobble(artiststr,titlestr,timestamp)
return 200,{"status":"ok"}
def validate_token(self,pathnodes,keys):
try:
token = keys.get("token").strip()