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

Minor cleanup and better logging

This commit is contained in:
krateng 2021-11-16 18:22:46 +01:00
parent 817d98e467
commit 26dfdfb569
6 changed files with 20 additions and 15 deletions

View File

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

View File

@ -36,7 +36,7 @@ def get_image_track_all(track):
else: else:
log("Could not get track image for " + str(track) + " from " + service.name) log("Could not get track image for " + str(track) + " from " + service.name)
except Exception as e: except Exception as e:
log("Error getting track image from " + service.name + ": " + str(e)) log("Error getting track image from " + service.name + ": " + repr(e))
def get_image_artist_all(artist): def get_image_artist_all(artist):
for service in services["metadata"]: for service in services["metadata"]:
try: try:
@ -47,7 +47,7 @@ def get_image_artist_all(artist):
else: else:
log("Could not get artist image for " + str(artist) + " from " + service.name) log("Could not get artist image for " + str(artist) + " from " + service.name)
except Exception as e: except Exception as e:
log("Error getting artist image from " + service.name + ": " + str(e)) log("Error getting artist image from " + service.name + ": " + repr(e))
@ -70,8 +70,7 @@ class GenericInterface:
# avoid constant disk access, restart on adding services is acceptable # avoid constant disk access, restart on adding services is acceptable
for key in self.settings: for key in self.settings:
self.settings[key] = get_settings(self.settings[key]) self.settings[key] = get_settings(self.settings[key])
try: self.authorize() self.authorize()
except: pass
def __init_subclass__(cls,abstract=False): def __init_subclass__(cls,abstract=False):
if not abstract: if not abstract:

View File

@ -21,9 +21,8 @@ class LastFM(MetadataInterface, ProxyScrobbleInterface):
metadata = { metadata = {
"trackurl": "https://ws.audioscrobbler.com/2.0/?method=track.getinfo&track={title}&artist={artist}&api_key={apikey}&format=json", "trackurl": "https://ws.audioscrobbler.com/2.0/?method=track.getinfo&track={title}&artist={artist}&api_key={apikey}&format=json",
"response_type":"json", "response_type":"json",
"response_parse_tree_track": ["track","album","image",3,"#text"], "response_parse_tree_track": ["track","album","image",-1,"#text"],
"required_settings": ["apikey"], "required_settings": ["apikey"],
"activated_setting": "METADATA_LASTFM"
} }
def get_image_artist(self,artist): def get_image_artist(self,artist):

View File

@ -20,7 +20,6 @@ class MusicBrainz(MetadataInterface):
"response_type":"json", "response_type":"json",
"response_parse_tree_track": ["images",0,"image"], "response_parse_tree_track": ["images",0,"image"],
"required_settings": [], "required_settings": [],
"activated_setting": "METADATA_MUSICBRAINZ"
} }
def get_image_artist(self,artist): def get_image_artist(self,artist):

View File

@ -2,6 +2,7 @@ from . import MetadataInterface, utf, b64
import urllib.parse, urllib.request import urllib.parse, urllib.request
import json import json
from threading import Timer from threading import Timer
from doreah.logging import log
class Spotify(MetadataInterface): class Spotify(MetadataInterface):
name = "Spotify" name = "Spotify"
@ -19,7 +20,6 @@ class Spotify(MetadataInterface):
"response_parse_tree_track": ["tracks","items",0,"album","images",0,"url"], "response_parse_tree_track": ["tracks","items",0,"album","images",0,"url"],
"response_parse_tree_artist": ["artists","items",0,"images",0,"url"], "response_parse_tree_artist": ["artists","items",0,"images",0,"url"],
"required_settings": ["apiid","secret"], "required_settings": ["apiid","secret"],
"activated_setting": "METADATA_SPOTIFY"
} }
def authorize(self): def authorize(self):
@ -32,10 +32,18 @@ class Spotify(MetadataInterface):
}, },
"data":bytes(urllib.parse.urlencode({"grant_type":"client_credentials"}),encoding="utf-8") "data":bytes(urllib.parse.urlencode({"grant_type":"client_credentials"}),encoding="utf-8")
} }
try:
req = urllib.request.Request(**keys) req = urllib.request.Request(**keys)
response = urllib.request.urlopen(req) response = urllib.request.urlopen(req)
responsedata = json.loads(response.read()) responsedata = json.loads(response.read())
if "error" in responsedata:
log("Error authenticating with Spotify: " + responsedata['error_description'])
expire = 3600
else:
expire = responsedata.get("expires_in",3600) expire = responsedata.get("expires_in",3600)
self.settings["token"] = responsedata["access_token"] self.settings["token"] = responsedata["access_token"]
except Exception as e:
log("Error while authenticating with Spotify: " + str(e))
expire = 3600
Timer(expire,self.authorize).start() Timer(expire,self.authorize).start()
return True return True

View File

@ -614,7 +614,7 @@ table.list td.chart div {
height:4px; height:4px;
*/ */
height:20px; height:20px;
background-color: var(--text-color-tertiary); background-color: var(--base-color-dark);
border-radius: 0px 30px 30px 0px; border-radius: 0px 30px 30px 0px;
background-image:url("/media/chartpos_normal.png"); background-image:url("/media/chartpos_normal.png");
background-position: right; background-position: right;