diff --git a/maloja/apis/_base.py b/maloja/apis/_base.py index 3ec2d3b..f2deff7 100644 --- a/maloja/apis/_base.py +++ b/maloja/apis/_base.py @@ -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) diff --git a/maloja/apis/audioscrobbler.py b/maloja/apis/audioscrobbler.py index df25651..7fff96b 100644 --- a/maloja/apis/audioscrobbler.py +++ b/maloja/apis/audioscrobbler.py @@ -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 diff --git a/maloja/apis/listenbrainz.py b/maloja/apis/listenbrainz.py index 16ee0e2..035aa06 100644 --- a/maloja/apis/listenbrainz.py +++ b/maloja/apis/listenbrainz.py @@ -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()