2018-12-16 19:52:13 +03:00
|
|
|
import urllib
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
2018-12-17 01:56:30 +03:00
|
|
|
def replacedict(keys,dbport):
|
2018-12-26 21:20:26 +03:00
|
|
|
from utilities import getArtistInfo
|
2018-12-27 05:09:29 +03:00
|
|
|
from htmlgenerators import clean, artistLink, artistLinks, trackLink, scrobblesTrackLink
|
2018-12-16 19:52:13 +03:00
|
|
|
|
2018-12-27 05:09:29 +03:00
|
|
|
clean(keys)
|
2018-12-17 17:10:10 +03:00
|
|
|
info = getArtistInfo(keys["artist"])
|
|
|
|
imgurl = info.get("image")
|
2018-12-28 20:06:09 +03:00
|
|
|
#desc = info.get("info")
|
2018-12-16 19:52:13 +03:00
|
|
|
|
2018-12-17 01:56:30 +03:00
|
|
|
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/artistinfo?artist=" + urllib.parse.quote(keys["artist"]))
|
|
|
|
db_data = json.loads(response.read())
|
|
|
|
scrobbles = str(db_data["scrobbles"])
|
|
|
|
pos = "#" + str(db_data["position"])
|
2018-12-17 18:33:26 +03:00
|
|
|
|
2018-12-17 01:56:30 +03:00
|
|
|
credited = db_data.get("replace")
|
|
|
|
includestr = " "
|
|
|
|
if credited is not None:
|
2018-12-22 14:47:49 +03:00
|
|
|
includestr = "Competing under " + artistLink(credited) + " (" + pos + ")"
|
2018-12-17 01:56:30 +03:00
|
|
|
pos = ""
|
|
|
|
included = db_data.get("associated")
|
|
|
|
if included is not None and included != []:
|
|
|
|
includestr = "associated: "
|
2018-12-27 05:09:29 +03:00
|
|
|
includestr += artistLinks(included)
|
2018-12-22 16:06:21 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/tracks?artist=" + urllib.parse.quote(keys["artist"]))
|
2018-12-16 19:52:13 +03:00
|
|
|
db_data = json.loads(response.read())
|
2018-12-22 14:47:49 +03:00
|
|
|
|
2018-12-22 16:06:21 +03:00
|
|
|
maxbar = db_data["list"][0]["scrobbles"]
|
2018-12-22 14:47:49 +03:00
|
|
|
html = "<table class='list'>"
|
2018-12-16 19:52:13 +03:00
|
|
|
for e in db_data["list"]:
|
2018-12-22 14:47:49 +03:00
|
|
|
html += "<tr>"
|
2018-12-27 05:09:29 +03:00
|
|
|
html += "<td class='artists'>" + artistLinks(e["track"]["artists"]) + "</td>"
|
|
|
|
html += "<td>" + trackLink(e["track"]) + "</td>"
|
|
|
|
html += "<td class='amount'>" + scrobblesTrackLink(e["track"],{},amount=e["scrobbles"]) + "</td>"
|
2018-12-28 20:06:09 +03:00
|
|
|
html += "<td class='bar'>" + scrobblesTrackLink(e["track"],{},percent=e["scrobbles"]*100/maxbar) + "</td>"
|
2018-12-22 14:47:49 +03:00
|
|
|
html += "</tr>"
|
|
|
|
html += "</table>"
|
2018-12-16 19:52:13 +03:00
|
|
|
|
|
|
|
|
2018-12-28 20:06:09 +03:00
|
|
|
return {"KEY_ARTISTNAME":keys["artist"],"KEY_ENC_ARTISTNAME":urllib.parse.quote(keys["artist"]),"KEY_IMAGEURL":imgurl, "KEY_DESCRIPTION":"","KEY_TRACKLIST":html,"KEY_SCROBBLES":scrobbles,"KEY_POSITION":pos,"KEY_ASSOCIATED":includestr}
|