maloja/website/scrobbles.py
Krateng 5f19e7b38e Significant rework of the architecture
* URL keys and internal keys are now being separated more cleanly
* HTML generation is split up into submodules that can be used by serveral websites
* HTML generation now talks directly to the database in most cases instead of calling the database server for json data
2019-02-20 18:22:45 +01:00

50 lines
1.7 KiB
Python

import urllib
import json
def instructions(keys,dbport):
from utilities import getArtistInfo, getTrackInfo
from htmlgenerators import getTimeDesc, artistLink, artistLinks, trackLink, keysToUrl, KeySplit
from htmlmodules import module_scrobblelist
filterkeys, timekeys, _, amountkeys = KeySplit(keys)
# describe the scope
limitstring = ""
if keys.get("title") is not None:
limitstring += "of " + trackLink({"title":keys.get("title"),"artists":keys.getall("artist")}) + " "
limitstring += "by " + artistLinks(keys.getall("artist"))
elif keys.get("artist") is not None:
limitstring += "by " + artistLink(keys.get("artist"))
if keys.get("associated") is not None:
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/artistinfo?artist=" + urllib.parse.quote(keys["artist"]))
db_data = json.loads(response.read())
moreartists = db_data["associated"]
if moreartists != []:
limitstring += " <span class='extra'>including " + artistLinks(moreartists) + "</span>"
html, amount, rep = module_scrobblelist(**filterkeys,**timekeys,**amountkeys)
# get image
if filterkeys.get("track") is not None:
imgurl = getTrackInfo(filterkeys.get("track")["artists"],filterkeys.get("track")["title"]).get("image")
elif filterkeys.get("artist") is not None:
imgurl = getArtistInfo(keys.get("artist")).get("image")
elif rep is not None:
imgurl = getTrackInfo(rep["artists"],rep["title"]).get("image")
else:
imgurl = ""
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
replace = {"KEY_SCROBBLELIST":html,"KEY_SCROBBLES":str(amount),"KEY_IMAGEURL":imgurl,"KEY_LIMITS":limitstring}
return (replace,pushresources)