2018-12-27 16:57:25 +03:00
|
|
|
import urllib
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
2019-02-17 16:25:40 +03:00
|
|
|
def instructions(keys,dbport):
|
2018-12-28 20:06:09 +03:00
|
|
|
from utilities import getArtistInfo, getTrackInfo
|
2018-12-27 16:57:25 +03:00
|
|
|
from htmlgenerators import clean, artistLink, artistLinks, trackLink, scrobblesTrackLink, keysToUrl, pickKeys, getTimeDesc
|
|
|
|
|
|
|
|
clean(keys)
|
|
|
|
limitkeys = pickKeys(keys,"artist","title")
|
2018-12-28 20:06:09 +03:00
|
|
|
info = getTrackInfo(keys.getall("artist"),keys.get("title"))
|
2018-12-27 16:57:25 +03:00
|
|
|
imgurl = info.get("image")
|
2019-02-17 16:25:40 +03:00
|
|
|
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
|
2018-12-27 16:57:25 +03:00
|
|
|
|
2019-02-15 17:18:57 +03:00
|
|
|
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/trackinfo?" + keysToUrl(limitkeys))
|
2018-12-27 16:57:25 +03:00
|
|
|
db_data = json.loads(response.read())
|
|
|
|
scrobblesnum = str(db_data["scrobbles"])
|
|
|
|
pos = "#" + str(db_data["position"])
|
|
|
|
|
|
|
|
|
2019-02-15 17:18:57 +03:00
|
|
|
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/scrobbles?" + keysToUrl(limitkeys))
|
2018-12-27 16:57:25 +03:00
|
|
|
db_data = json.loads(response.read())
|
|
|
|
scrobbles = db_data["list"]
|
|
|
|
|
|
|
|
|
|
|
|
# build list
|
|
|
|
html = "<table class='list'>"
|
|
|
|
for s in scrobbles:
|
|
|
|
html += "<tr>"
|
|
|
|
html += "<td class='time'>" + getTimeDesc(s["time"]) + "</td>"
|
|
|
|
html += "<td class='artists'>" + artistLinks(s["artists"]) + "</td>"
|
|
|
|
html += "<td class='title'>" + trackLink({"artists":s["artists"],"title":s["title"]}) + "</td>"
|
|
|
|
html += "</tr>"
|
|
|
|
html += "</table>"
|
|
|
|
|
|
|
|
|
2019-02-17 16:25:40 +03:00
|
|
|
replace = {"KEY_TRACKTITLE":limitkeys.get("title"),"KEY_ARTISTS":artistLinks(limitkeys.getall("artist")),"KEY_SCROBBLES":scrobblesnum,"KEY_IMAGEURL":imgurl,
|
|
|
|
"KEY_SCROBBLELINK":keysToUrl(limitkeys),"KEY_SCROBBLELIST":html,"KEY_POSITION":pos}
|
|
|
|
|
|
|
|
return (replace,pushresources)
|