mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Audioscrobbler protocol should now work as well
This commit is contained in:
parent
a4812a66da
commit
879b3cf170
@ -6,6 +6,7 @@ from ._exceptions import *
|
||||
from copy import deepcopy
|
||||
from types import FunctionType
|
||||
import sys
|
||||
import datetime
|
||||
|
||||
from doreah.logging import log
|
||||
|
||||
@ -87,6 +88,7 @@ class APIHandler:
|
||||
def scrobble(self,artiststr,titlestr,time=None,duration=None,album=None):
|
||||
logmsg = "Incoming scrobble (API: {api}): ARTISTS: {artiststr}, TRACK: {titlestr}"
|
||||
log(logmsg.format(api=self.__apiname__,artiststr=artiststr,titlestr=titlestr))
|
||||
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)
|
||||
|
@ -53,7 +53,10 @@ class Audioscrobbler(APIHandler):
|
||||
if "track" in keys and "artist" in keys:
|
||||
artiststr,titlestr = keys["artist"], keys["track"]
|
||||
#(artists,title) = cla.fullclean(artiststr,titlestr)
|
||||
timestamp = int(keys["timestamp"])
|
||||
try:
|
||||
timestamp = int(keys["timestamp"])
|
||||
except:
|
||||
timestamp = None
|
||||
#database.createScrobble(artists,title,timestamp)
|
||||
self.scrobble(artiststr,titlestr,time=timestamp)
|
||||
return 200,{"scrobbles":{"@attr":{"ignored":0}}}
|
||||
@ -66,3 +69,19 @@ class Audioscrobbler(APIHandler):
|
||||
#database.createScrobble(artists,title,timestamp)
|
||||
self.scrobble(artiststr,titlestr,time=timestamp)
|
||||
return 200,{"scrobbles":{"@attr":{"ignored":0}}}
|
||||
|
||||
|
||||
import hashlib
|
||||
import random
|
||||
|
||||
def md5(input):
|
||||
m = hashlib.md5()
|
||||
m.update(bytes(input,encoding="utf-8"))
|
||||
return m.hexdigest()
|
||||
|
||||
def generate_key(ls):
|
||||
key = ""
|
||||
for i in range(64):
|
||||
key += str(random.choice(list(range(10)) + list("abcdefghijklmnopqrstuvwxyz") + list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")))
|
||||
ls.append(key)
|
||||
return key
|
||||
|
@ -44,7 +44,7 @@ class Listenbrainz(APIHandler):
|
||||
try:
|
||||
timestamp = int(listen["listened_at"])
|
||||
except:
|
||||
timestamp = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())
|
||||
timestamp = None
|
||||
except:
|
||||
raise MalformedJSONException()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user