Fixed Spotify auth if not in use, fix GH-87

This commit is contained in:
krateng 2021-11-21 17:14:22 +01:00
parent 2101223440
commit 898dd9735c
2 changed files with 25 additions and 25 deletions

View File

@ -5,7 +5,7 @@ author = {
"email":"maloja@dev.krateng.ch",
"github": "krateng"
}
version = 2,12,16
version = 2,12,17
versionstr = ".".join(str(n) for n in version)
links = {
"pypi":"malojaserver",

View File

@ -24,6 +24,9 @@ class Spotify(MetadataInterface):
def authorize(self):
if self.active_metadata():
try:
keys = {
"url":"https://accounts.spotify.com/api/token",
"method":"POST",
@ -32,7 +35,6 @@ class Spotify(MetadataInterface):
},
"data":bytes(urllib.parse.urlencode({"grant_type":"client_credentials"}),encoding="utf-8")
}
try:
req = urllib.request.Request(**keys)
response = urllib.request.urlopen(req)
responsedata = json.loads(response.read())
@ -43,8 +45,6 @@ class Spotify(MetadataInterface):
expire = responsedata.get("expires_in",3600)
self.settings["token"] = responsedata["access_token"]
log("Successfully authenticated with Spotify")
Timer(expire,self.authorize).start()
except Exception as e:
log("Error while authenticating with Spotify: " + repr(e))
expire = 1200
Timer(expire,self.authorize).start()
return True