diff --git a/maloja/__pkginfo__.py b/maloja/__pkginfo__.py index df8e0a9..36b33e3 100644 --- a/maloja/__pkginfo__.py +++ b/maloja/__pkginfo__.py @@ -4,7 +4,7 @@ # you know what f*ck it # this is hardcoded for now because of that damn project / package name discrepancy # i'll fix it one day -VERSION = "3.0.0-dev" +VERSION = "3.0.0-alpha.1" HOMEPAGE = "https://github.com/krateng/maloja" diff --git a/maloja/apis/_apikeys.py b/maloja/apis/_apikeys.py index cdd153e..67096ab 100644 --- a/maloja/apis/_apikeys.py +++ b/maloja/apis/_apikeys.py @@ -3,6 +3,7 @@ from ..globalconf import apikeystore # skip regular authentication if api key is present in request # an api key now ONLY permits scrobbling tracks, no other admin tasks def api_key_correct(request): + request.malojaclient = None args = request.params try: args.update(request.json) @@ -13,7 +14,13 @@ def api_key_correct(request): elif "apikey" in args: apikey = args.pop("apikey") else: return False - return checkAPIkey(apikey) + if checkAPIkey(apikey): + request.malojaclient = [c for c in apikeystore if apikeystore[c]==apikey][0] + return True + else: + return False + + def checkAPIkey(key): return apikeystore.check_key(key) def allAPIkeys(): diff --git a/maloja/apis/native_v1.py b/maloja/apis/native_v1.py index 0a4b10f..4bf505b 100644 --- a/maloja/apis/native_v1.py +++ b/maloja/apis/native_v1.py @@ -234,9 +234,10 @@ def post_scrobble(artist:Multi=None,**keys): #artists = "/".join(artist) keys['artists'] = [artist] if artist is not None else keys.get("artists") keys['fix'] = keys.get("nofix") is None - if time is not None: time = int(time) + if keys.get('time') is not None: keys['time'] = int(time) - return incoming_scrobble(**keys) + return incoming_scrobble(**keys,client=request.malojaclient) + # TODO: malojaclient needs to be converted to proper argument in doreah diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 91a480c..d48d5ef 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -72,7 +72,10 @@ coa = CollectorAgent() -def incoming_scrobble(artists,title,album=None,albumartists=None,duration=None,length=None,time=None,fix=True): +def incoming_scrobble(artists,title,album=None,albumartists=None,duration=None,length=None,time=None,fix=True,client=None,**kwargs): + # TODO: just collecting all extra kwargs now. at some point, rework the authenticated api with alt function + # to actually look at the converted args instead of the request object and remove the key + # so that this function right here doesnt get the key passed to it if time is None: time = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()) @@ -98,9 +101,10 @@ def incoming_scrobble(artists,title,album=None,albumartists=None,duration=None,l "length":None }, "duration":duration, - "origin":"generic" + "origin":"client:" + client if client else "generic" } + sqldb.add_scrobble(scrobbledict) proxy_scrobble_all(artists,title,time)