1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Database improvements and top tracks web interface

This commit is contained in:
Krateng
2018-12-22 14:06:21 +01:00
parent eb9c9b2f69
commit dfe46d0242
8 changed files with 134 additions and 18 deletions

View File

@@ -23,7 +23,7 @@
</tr>
</table>
<h2>Tracks</h2>
<h2><a href='/toptracks?artist=KEY_ENC_ARTISTNAME'>Tracks</a></h2>
KEY_TRACKLIST
</body>

View File

@@ -27,19 +27,37 @@ def replacedict(keys,dbport):
includestr += ", ".join([artistLink(a) for a in included]) #"<a href=/artist?artist=" + urllib.parse.quote(a) + ">" + a + "</a>, "
#includestr = includestr[:-2]
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/tracks?artist=" + urllib.parse.quote(keys["artist"]))
# response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/tracks?artist=" + urllib.parse.quote(keys["artist"]))
# db_data = json.loads(response.read())
#
# html = "<table class='list'>"
# for e in db_data["list"]:
# html += "<tr>"
# html += "<td class='artists'>"
# links = [artistLink(a) for a in e["artists"]]
# html += ", ".join(links)
# html += "</td><td class='title'>" + e["title"] + "</td>"
# html += "</tr>"
# html += "</table>"
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/tracks?artist=" + urllib.parse.quote(keys["artist"]))
db_data = json.loads(response.read())
maxbar = db_data["list"][0]["scrobbles"]
html = "<table class='list'>"
for e in db_data["list"]:
html += "<tr>"
html += "<td class='artists'>"
links = [artistLink(a) for a in e["artists"]]
links = [artistLink(a) for a in e["track"]["artists"]]
html += ", ".join(links)
html += "</td><td class='title'>" + e["title"] + "</td>"
html += "</td><td class='title'>" + e["track"]["title"] + "</td>"
html += "</td><td class='amount'>" + str(e["scrobbles"]) + "</td>"
html += "<td class='bar'><div style='width:" + str(e["scrobbles"]/maxbar * 100) + "%;'></div></td>"
html += "</tr>"
html += "</table>"
return {"KEY_ARTISTNAME":keys["artist"],"KEY_ENC_ARTISTNAME":urllib.parse.quote(keys["artist"]),"KEY_IMAGEURL":imgurl, "KEY_DESCRIPTION":desc,"KEY_TRACKLIST":html,"KEY_SCROBBLES":scrobbles,"KEY_POSITION":pos,"KEY_ASSOCIATED":includestr}

View File

@@ -51,6 +51,11 @@ table.top_info td.text .stats {
text-align:right;
color:grey;
}
.extra {
color:gray; /*sue me*/
font-size:80%;
}
a {
cursor:pointer;
}

View File

@@ -18,7 +18,12 @@ def replacedict(keys,dbport):
limitstring = ""
if keys.get("artist") is not None:
#limitstring += "by <a href='/artist?artist=" + urllib.parse.quote(keys.get("artist")) + "'>" + keys.get("artist") + "</a> "
limitstring += "by " + artistLink(keys.get("artist"))
limitstring += "by " + artistLink(keys.get("artist"))
if keys.get("associated") is not None:
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/artistinfo?artist=" + urllib.parse.quote(keys["artist"]))
db_data = json.loads(response.read())
moreartists = db_data["associated"]
limitstring += " <span class='extra'>including " + ", ".join(moreartists) + "</span>"
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + extrakeys)
db_data = json.loads(response.read())

View File

@@ -32,8 +32,10 @@ def replacedict(keys,dbport):
html += "<td class='rank'>#" + str(i) + "</td><td class='artist'>"
#html += "<a href=/artist?artist=" + urllib.parse.quote(e["artist"]) + ">" + e["artist"] + "</a>"
html += artistLink(e["artist"])
html += "</td><td class='amount'><a href='/scrobbles?artist=" + urllib.parse.quote(e["artist"]) + "&" + extrakeys + "'>" + str(e["scrobbles"]) + "</a></td>"
html += "<td class='bar'><a href='/scrobbles?artist=" + urllib.parse.quote(e["artist"]) + "&" + extrakeys + "'><div style='width:" + str(e["scrobbles"]/maxbar * 100) + "%;'></div></a></td>"
if (e["counting"] != []):
html += " <span class='extra'>incl. " + ", ".join([artistLink(a) for a in e["counting"]]) + "</span>"
html += "</td><td class='amount'><a href='/scrobbles?artist=" + urllib.parse.quote(e["artist"]) + "&associated&" + extrakeys + "'>" + str(e["scrobbles"]) + "</a></td>"
html += "<td class='bar'><a href='/scrobbles?artist=" + urllib.parse.quote(e["artist"]) + "&associated&" + extrakeys + "'><div style='width:" + str(e["scrobbles"]/maxbar * 100) + "%;'></div></a></td>"
html += "</tr>"
i += 1
html += "</table>"

29
website/toptracks.html Normal file
View File

@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Maloja - Top Tracks in KEY_RANGE</title>
<link rel="stylesheet" href="maloja.css" />
</head>
<body>
<table class="top_info">
<tr>
<td class="image">
<div style="background-image:url('KEY_TOPARTIST_IMAGEURL')"></div>
</td>
<td class="text">
<h1>Top Tracks</h1><br/>
<span>KEY_LIMITS</span>
<p class="stats">KEY_SCROBBLES Scrobbles</p>
</td>
</tr>
</table>
KEY_TRACKLIST
</body>
</html>

48
website/toptracks.py Normal file
View File

@@ -0,0 +1,48 @@
import urllib
import json
def replacedict(keys,dbport):
from utilities import getArtistInfo, artistLink
#hand down the since and from arguments
extrakeys = urllib.parse.urlencode(keys,quote_via=urllib.parse.quote,safe="/")
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/tracks?" + extrakeys)
db_data = json.loads(response.read())
charts = db_data["list"][:50]
limitstring = ""
if keys.get("artist") is not None:
topartist = keys.get("artist")
limitstring += "by " + artistLink(keys.get("artist"))
else:
topartist = charts[0]["track"]["artists"][0] #for now
info = getArtistInfo(topartist)
imgurl = info.get("image")
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + extrakeys)
db_data = json.loads(response.read())
scrobblelist = db_data["list"]
scrobbles = len(scrobblelist)
maxbar = charts[0]["scrobbles"]
i = 1
html = "<table class='list'>"
for e in charts:
html += "<tr>"
html += "<td class='rank'>#" + str(i) + "</td><td class='artists'>"
html += ", ".join([artistLink(a) for a in e["track"]["artists"]])
html += "</td><td class='title'>" + e["track"]["title"]
html += "</td><td class='amount'>" + str(e["scrobbles"]) + "</td>"
html += "<td class='bar'><div style='width:" + str(e["scrobbles"]/maxbar * 100) + "%;'></div>"
html += "</td>"
html += "</tr>"
i += 1
html += "</table>"
return {"KEY_TOPARTIST_IMAGEURL":imgurl,"KEY_SCROBBLES":str(scrobbles),"KEY_TRACKLIST":html,"KEY_LIMITS":limitstring}