2018-12-19 18:11:10 +03:00
|
|
|
import urllib
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
2019-02-17 16:25:40 +03:00
|
|
|
def instructions(keys,dbport):
|
2018-12-29 02:08:00 +03:00
|
|
|
from utilities import getArtistInfo, getTrackInfo
|
2019-02-20 20:22:45 +03:00
|
|
|
from htmlgenerators import getTimeDesc, artistLink, artistLinks, trackLink, keysToUrl, KeySplit
|
|
|
|
from htmlmodules import module_scrobblelist
|
2018-12-19 18:11:10 +03:00
|
|
|
|
2018-12-27 05:09:29 +03:00
|
|
|
|
2019-02-20 20:22:45 +03:00
|
|
|
filterkeys, timekeys, _, amountkeys = KeySplit(keys)
|
2018-12-23 01:19:52 +03:00
|
|
|
|
2018-12-27 05:09:29 +03:00
|
|
|
# describe the scope
|
|
|
|
limitstring = ""
|
2018-12-24 23:25:09 +03:00
|
|
|
if keys.get("title") is not None:
|
2018-12-27 05:09:29 +03:00
|
|
|
limitstring += "of " + trackLink({"title":keys.get("title"),"artists":keys.getall("artist")}) + " "
|
|
|
|
limitstring += "by " + artistLinks(keys.getall("artist"))
|
2018-12-24 23:25:09 +03:00
|
|
|
|
|
|
|
elif keys.get("artist") is not None:
|
2018-12-27 05:09:29 +03:00
|
|
|
limitstring += "by " + artistLink(keys.get("artist"))
|
2018-12-22 16:06:21 +03:00
|
|
|
if keys.get("associated") is not None:
|
2019-02-15 17:18:57 +03:00
|
|
|
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/artistinfo?artist=" + urllib.parse.quote(keys["artist"]))
|
2018-12-22 16:06:21 +03:00
|
|
|
db_data = json.loads(response.read())
|
2018-12-27 05:09:29 +03:00
|
|
|
moreartists = db_data["associated"]
|
2018-12-23 01:19:52 +03:00
|
|
|
if moreartists != []:
|
2018-12-27 05:09:29 +03:00
|
|
|
limitstring += " <span class='extra'>including " + artistLinks(moreartists) + "</span>"
|
2018-12-23 01:19:52 +03:00
|
|
|
|
2019-02-20 20:22:45 +03:00
|
|
|
|
|
|
|
|
|
|
|
html, amount, rep = module_scrobblelist(**filterkeys,**timekeys,**amountkeys)
|
2018-12-27 05:09:29 +03:00
|
|
|
|
2018-12-29 02:08:00 +03:00
|
|
|
# get image
|
2019-02-20 20:22:45 +03:00
|
|
|
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:
|
2018-12-27 05:09:29 +03:00
|
|
|
imgurl = getArtistInfo(keys.get("artist")).get("image")
|
2019-02-20 20:22:45 +03:00
|
|
|
elif rep is not None:
|
|
|
|
imgurl = getTrackInfo(rep["artists"],rep["title"]).get("image")
|
2018-12-23 01:19:52 +03:00
|
|
|
else:
|
2018-12-27 05:09:29 +03:00
|
|
|
imgurl = ""
|
2019-02-20 20:22:45 +03:00
|
|
|
|
2019-02-17 16:25:40 +03:00
|
|
|
|
|
|
|
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
|
2018-12-23 01:19:52 +03:00
|
|
|
|
2019-02-20 20:22:45 +03:00
|
|
|
|
|
|
|
replace = {"KEY_SCROBBLELIST":html,"KEY_SCROBBLES":str(amount),"KEY_IMAGEURL":imgurl,"KEY_LIMITS":limitstring}
|
2019-02-17 16:25:40 +03:00
|
|
|
|
|
|
|
return (replace,pushresources)
|
2018-12-19 18:11:10 +03:00
|
|
|
|