Last FM key is now handled by settings as well

This commit is contained in:
Krateng 2019-03-28 15:54:39 +01:00
parent 1dcaa1c24d
commit 03efd4fa62
4 changed files with 35 additions and 16 deletions

View File

@ -17,7 +17,7 @@ def config(defaultextension=".ini",files=["settings.ini","settings.conf","config
_onlytext = onlytext
global Settings, get_settings, set_settings, update
global Settings, get_settings, update_settings, update
# manager object so we can read settings once and retain them
@ -116,11 +116,11 @@ def config(defaultextension=".ini",files=["settings.ini","settings.conf","config
# specific keys requested
else:
if len(keys) == 1: return allsettings[keys[0]]
else: return [allsettings[k] for k in keys]
if len(keys) == 1: return allsettings.get(keys[0])
else: return [allsettings.get(k) for k in keys]
def set_settings(file,settings):
def update_settings(file,settings):
if not os.path.exists(file): return
@ -180,7 +180,7 @@ def config(defaultextension=".ini",files=["settings.ini","settings.conf","config
else:
usersettings = get_settings(files=[target],raw=True)
shutil.copyfile(source,target)
set_settings(target,usersettings)
update_settings(target,usersettings)
# initial config on import, set everything to default

37
maloja
View File

@ -5,6 +5,7 @@ import sys
import signal
import os
import stat
from doreah import settings
neededmodules = [
@ -20,6 +21,9 @@ recommendedmodules = [
SOURCE_URL = "https://github.com/krateng/maloja/archive/master.zip"
settings.config(files=["settings/default.ini","settings/settings.ini"])
def blue(txt): return "\033[94m" + txt + "\033[0m"
def green(txt): return "\033[92m" + txt + "\033[0m"
def yellow(txt): return "\033[93m" + txt + "\033[0m"
@ -37,18 +41,33 @@ def gotodir():
def setup():
# LASTFM API KEY
if os.path.exists("./apikey"):
with open("apikey","r") as keyfile:
apikey = keyfile.read().replace("\n","")
if apikey == "NONE": print("Currently not using an API key for image display. Only local images will be used.")
else:
# LASTFM API KEY
key = settings.get_settings("LASTFM_API_KEY")
if key is None:
print("Currently not using an API key for image display. Only local images will be used.")
elif key == "ASK":
print("Please enter your Last.FM API key. If you do not want to display artist and track images, simply leave this empty and press Enter.")
key = input()
if key == "": key = "NONE"
with open("apikey","w") as keyfile:
keyfile.write(key)
if key == "": key = None
settings.update_settings("settings/settings.ini",{"LASTFM_API_KEY":key})
# TODO: Make sure we set the setting even if file doesnt exist
else:
print("Last.FM API key found.")
# if os.path.exists("./apikey"):
# with open("apikey","r") as keyfile:
# apikey = keyfile.read().replace("\n","")
#
# if apikey == "NONE": print("Currently not using an API key for image display. Only local images will be used.")
# else:
# print("Please enter your Last.FM API key. If you do not want to display artist and track images, simply leave this empty and press Enter.")
# key = input()
# if key == "": key = "NONE"
# with open("apikey","w") as keyfile:
# keyfile.write(key)
# OWN API KEY
if os.path.exists("./clients/authenticated_machines.tsv"):

View File

@ -5,4 +5,4 @@ API_PORT = 42011
[Third Party Services]
LASTFM_API_KEY = None
LASTFM_API_KEY = "ASK"

View File

@ -387,7 +387,7 @@ def getArtistImage(artist,fast=False):
# do we have an api key?
apikey = settings.get_settings("LASTFM_API_KEY")
if apikey is None: return "" # DO NOT CACHE THAT
# fast request only retuns cached and local results, generates redirect link for rest
if fast: return "/image?artist=" + urllib.parse.quote(artist)