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

@ -329,7 +329,7 @@ def artistInfo():
artist = keys.get("artist")
charts = db_aggregate(by="ARTIST")
scrobbles = len(db_query(artist=artist)) #we cant take the scrobble number from the charts because that includes all countas scrobbles
scrobbles = len(db_query(artists=[artist])) #we cant take the scrobble number from the charts because that includes all countas scrobbles
try:
c = [e for e in charts if e["artist"] == artist][0]
others = coa.getAllAssociated(artist)

View File

@ -2,6 +2,7 @@
from bottle import Bottle, route, get, post, error, run, template, static_file, request, response, FormsDict
from importlib.machinery import SourceFileLoader
from utilities import removeIdentical
import _thread
import waitress
import urllib.request
@ -89,7 +90,8 @@ def static(name):
@webserver.route("/<name>")
def static_html(name):
keys = FormsDict.decode(request.query)
keys = removeIdentical(FormsDict.decode(request.query))
# If a python file exists, it provides the replacement dict for the html file
if os.path.exists("website/" + name + ".py"):

View File

@ -231,7 +231,27 @@ def cacheImage(url,path,filename):
def artistLink(name):
import urllib
return "<a href='/artist?artist=" + urllib.parse.quote(name) + "'>" + name + "</a>"
# necessary because urllib.parse.urlencode doesnt handle multidicts
def keysToUrl(keys):
import urllib
st = ""
for k in removeIdentical(keys):
values = keys.getall(k)
st += "&".join([urllib.parse.urlencode({k:v}) for v in values])
st += "&"
return st
def removeIdentical(keys):
from bottle import FormsDict
new = FormsDict()
for k in keys:
values = set(keys.getall(k))
for v in values:
new.append(k,v)
return new
def getTimeDesc(timestamp):
import datetime

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