2019-04-09 14:34:06 +03:00
|
|
|
import urllib
|
|
|
|
import database
|
|
|
|
|
|
|
|
|
|
|
|
def instructions(keys):
|
|
|
|
from utilities import getArtistImage, getTrackImage
|
|
|
|
from htmlgenerators import artistLink, artistLinks, trackLink, scrobblesLink
|
2019-04-23 18:47:49 +03:00
|
|
|
from urihandler import compose_querystring, uri_to_internal, internal_to_uri
|
2019-04-09 14:34:06 +03:00
|
|
|
from htmlmodules import module_performance, module_filterselection
|
|
|
|
from malojatime import range_desc, delimit_desc
|
|
|
|
|
2019-06-17 16:07:23 +03:00
|
|
|
filterkeys, timekeys, delimitkeys, paginatekeys = uri_to_internal(keys)
|
2019-04-09 14:34:06 +03:00
|
|
|
|
2019-04-23 18:47:49 +03:00
|
|
|
#equivalent pulse chart
|
2019-06-17 16:07:23 +03:00
|
|
|
pulselink_keys = internal_to_uri({**filterkeys,**timekeys,**delimitkeys,**paginatekeys})
|
2019-04-23 18:47:49 +03:00
|
|
|
pulselink = "/pulse?" + compose_querystring(pulselink_keys)
|
|
|
|
|
|
|
|
pulselink = "<a href=\"" + pulselink + "\"><span>View Pulse</span></a>"
|
|
|
|
|
2019-04-09 14:34:06 +03:00
|
|
|
|
|
|
|
# describe the scope (and creating a key for the relevant artist or track)
|
|
|
|
limitstring = ""
|
|
|
|
#limitkey = {}
|
|
|
|
if filterkeys.get("track") is not None:
|
|
|
|
#limitkey["track"] = {"artists":keys.getall("artist"),"title":keys.get("title")}
|
|
|
|
limitstring += "of " + trackLink(filterkeys["track"]) + " "
|
|
|
|
limitstring += "by " + artistLinks(filterkeys["track"]["artists"])
|
|
|
|
|
|
|
|
elif filterkeys.get("artist") is not None:
|
|
|
|
#limitkey["artist"], limitkey["associated"] = keys.get("artist"), (keys.get("associated")!=None)
|
|
|
|
limitstring += "of " + artistLink(filterkeys.get("artist"))
|
2019-04-12 18:57:28 +03:00
|
|
|
# associated are counted by default
|
|
|
|
data = database.artistInfo(filterkeys["artist"])
|
|
|
|
moreartists = data["associated"]
|
|
|
|
if moreartists != []:
|
|
|
|
limitstring += " <span class='extra'>including " + artistLinks(moreartists) + "</span>"
|
2019-04-09 14:34:06 +03:00
|
|
|
|
2019-04-10 16:45:50 +03:00
|
|
|
limitstring += " " + timekeys["timerange"].desc(prefix=True)
|
2019-04-09 14:34:06 +03:00
|
|
|
|
|
|
|
delimitstring = delimit_desc(**delimitkeys)
|
|
|
|
|
|
|
|
html_filterselector = module_filterselection(keys,delimit=True)
|
|
|
|
|
|
|
|
|
|
|
|
# get image
|
|
|
|
if filterkeys.get("track") is not None:
|
|
|
|
imgurl = getTrackImage(filterkeys.get("track")["artists"],filterkeys.get("track")["title"])
|
|
|
|
elif filterkeys.get("artist") is not None:
|
|
|
|
imgurl = getArtistImage(keys.get("artist"))
|
|
|
|
else:
|
|
|
|
imgurl = ""
|
|
|
|
|
|
|
|
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-06-17 16:07:23 +03:00
|
|
|
html_performance = module_performance(**filterkeys,**timekeys,**delimitkeys,**paginatekeys)
|
2019-04-09 14:34:06 +03:00
|
|
|
|
2019-04-23 18:47:49 +03:00
|
|
|
replace = {
|
|
|
|
"KEY_PULSE_LINK":pulselink,
|
|
|
|
"KEY_PERFORMANCE_TABLE":html_performance,
|
2019-04-09 14:34:06 +03:00
|
|
|
"KEY_IMAGEURL":imgurl,
|
|
|
|
"KEY_LIMITS":limitstring,
|
|
|
|
"KEY_PULSEDETAILS":delimitstring,
|
|
|
|
"KEY_FILTERSELECTOR":html_filterselector}
|
|
|
|
|
|
|
|
return (replace,pushresources)
|