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

Can now show scrobbles of tracks

This commit is contained in:
Krateng
2018-12-24 21:25:09 +01:00
parent ca28ba9431
commit bed50452b9
5 changed files with 43 additions and 14 deletions

View File

@@ -3,23 +3,27 @@ import json
def replacedict(keys,dbport):
from utilities import getArtistInfo, getTimeDesc, artistLink
from utilities import getArtistInfo, getTimeDesc, artistLink, keysToUrl
#hand down the since and from arguments
extrakeys = urllib.parse.urlencode(keys)
#extrakeys = urllib.parse.urlencode(keys,doseq=True)
extrakeys = keysToUrl(keys)
limitstring = ""
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + extrakeys)
db_data = json.loads(response.read())
scrobbles = db_data["list"]
if keys.get("artist") is not None:
if keys.get("title") is not None:
limitstring += "of " + keys.get("title") + " "
limitstring += "by " + ", ".join([artistLink(a) for a in keys.getall("artist")])
latestartist = keys.get("artist")
limitstring += "by " + artistLink(keys.get("artist"))
elif keys.get("artist") is not None:
latestartist = keys.get("artist")
limitstring += "by " + artistLink(keys.get("artist")) #if we dont specifiy a title, we filter by one artist, which means only one artist is allowed
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())

View File

@@ -3,13 +3,16 @@ import json
def replacedict(keys,dbport):
from utilities import getArtistInfo, artistLink
from utilities import getArtistInfo, artistLink, keysToUrl
# we don't use the associated key for top tracks so we don't wanna hand it down to functions we're calling
keys.pop("associated",None)
#hand down the since and from arguments
extrakeys = urllib.parse.urlencode(keys,quote_via=urllib.parse.quote,safe="/")
# I should probably add a separate variable for keys that are passed to db functions and keys that are inherited to links (usually only time)
#extrakeys = keysToUrl(keys)
# top tracks should always be of one artist
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/tracks?" + extrakeys)
db_data = json.loads(response.read())
@@ -18,8 +21,8 @@ def replacedict(keys,dbport):
if keys.get("artist") is not None:
topartist = keys.get("artist")
limitstring += "by " + artistLink(keys.get("artist"))
#limitstring += "by " + ", ".join([artistLink(a) for a in keys.getall("artist")])
limitstring = "by " + artistLink(keys.get("artist"))
else:
topartist = charts[0]["track"]["artists"][0] #for now
@@ -42,8 +45,8 @@ def replacedict(keys,dbport):
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><td class='amount'><a href='/scrobbles?" + "&".join(["artist=" + urllib.parse.quote(a) for a in e["track"]["artists"]]) + "&title=" + urllib.parse.quote(e["track"]["title"]) + "&" + extrakeys + "'>" + str(e["scrobbles"]) + "</a></td>"
html += "<td class='bar'><a href='/scrobbles?" + "&".join(["artist=" + urllib.parse.quote(a) for a in e["track"]["artists"]]) + "&title=" + urllib.parse.quote(e["track"]["title"]) + "&" + extrakeys + "'><div style='width:" + str(e["scrobbles"]/maxbar * 100) + "%;'></div></a>"
html += "</td>"
html += "</tr>"
i += 1