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

Modularized track and artist lists

This commit is contained in:
Krateng 2019-04-07 14:07:50 +02:00
parent 549fc09e7b
commit a6472c11b0
3 changed files with 47 additions and 29 deletions

View File

@ -1,9 +1,30 @@
import urllib
from bottle import FormsDict
import datetime
from malojatime import time_fix, internal_to_uri
from malojatime import uri_to_internal, internal_to_uri
# returns the proper column(s) for an artist or track
def entity_column(element,counting=[],image=None):
html = ""
if image is not None:
html += """<td class='icon'><div style="background-image:url('""" + image + """')"></div></td>"""
if "artists" in element:
# track
html += "<td class='artists'>" + artistLinks(element["artists"]) + "</td>"
html += "<td class='title'>" + trackLink({"artists":element["artists"],"title":element["title"]}) + "</td>"
else:
# artist
html += "<td class='artist'>" + artistLink(element)
if (counting != []):
html += " <span class='extra'>incl. " + ", ".join([artistLink(a) for a in counting]) + "</span>"
html += "</td>"
return html
def artistLink(name):
return "<a href='/artist?artist=" + urllib.parse.quote(name) + "'>" + name + "</a>"

View File

@ -42,9 +42,9 @@ def module_scrobblelist(max_=None,pictures=False,shortTimeDesc=False,earlystop=F
html += "<tr>"
html += "<td class='time'>" + time_desc(s["time"],short=shortTimeDesc) + "</td>"
if pictures:
html += """<td class='icon'><div style="background-image:url('""" + scrobbleimages[i] + """')"></div></td>"""
html += "<td class='artists'>" + artistLinks(s["artists"]) + "</td>"
html += "<td class='title'>" + trackLink({"artists":s["artists"],"title":s["title"]}) + "</td>"
img = scrobbleimages[i]
else: img = None
html += entity_column(s,image=img)
# Alternative way: Do it in one cell
#html += "<td class='title'><span>" + artistLinks(s["artists"]) + "</span> — " + trackLink({"artists":s["artists"],"title":s["title"]}) + "</td>"
html += "</tr>"
@ -142,8 +142,7 @@ def module_trackcharts(max_=None,**kwargs):
else:
html += "<td class='ranksame' title='Unchanged'>➡</td>"
# track
html += "<td class='artists'>" + artistLinks(e["track"]["artists"]) + "</td>"
html += "<td class='title'>" + trackLink(e["track"]) + "</td>"
html += entity_column(e["track"])
# scrobbles
html += "<td class='amount'>" + scrobblesTrackLink(e["track"],kwargs_time,amount=e["scrobbles"]) + "</td>"
html += "<td class='bar'>" + scrobblesTrackLink(e["track"],kwargs_time,percent=e["scrobbles"]*100/maxbar) + "</td>"
@ -204,10 +203,7 @@ def module_artistcharts(max_=None,**kwargs):
else:
html += "<td class='ranksame' title='Unchanged'>➡</td>"
# artist
html += "<td class='artist'>" + artistLink(e["artist"])
if (e["counting"] != []):
html += " <span class='extra'>incl. " + ", ".join([artistLink(a) for a in e["counting"]]) + "</span>"
html += "</td>"
html += entity_column(e["artist"],counting=e["counting"])
# scrobbles
html += "<td class='amount'>" + scrobblesArtistLink(e["artist"],kwargs_time,amount=e["scrobbles"],associated=True) + "</td>"
html += "<td class='bar'>" + scrobblesArtistLink(e["artist"],kwargs_time,percent=e["scrobbles"]*100/maxbar,associated=True) + "</td>"
@ -266,9 +262,9 @@ def module_toptracks(pictures=True,**kwargs):
html += "<td class='bar'>" + "" + "</td>"
else:
if pictures:
html += """<td class='icon'><div style="background-image:url('""" + getTrackImage(e["track"]["artists"],e["track"]["title"],fast=True) + """')"></div></td>"""
html += "<td class='artists'>" + artistLinks(e["track"]["artists"]) + "</td>"
html += "<td class='title'>" + trackLink(e["track"]) + "</td>"
img = getTrackImage(e["track"]["artists"],e["track"]["title"],fast=True)
else: img = None
html += entity_column(e["track"],image=img)
html += "<td class='amount'>" + scrobblesTrackLink(e["track"],{"since":fromstr,"to":tostr},amount=e["scrobbles"]) + "</td>"
html += "<td class='bar'>" + scrobblesTrackLink(e["track"],{"since":fromstr,"to":tostr},percent=e["scrobbles"]*100/maxbar) + "</td>"
html += "</tr>"
@ -321,11 +317,9 @@ def module_topartists(pictures=True,**kwargs):
html += "<td class='bar'>" + "" + "</td>"
else:
if pictures:
html += """<td class='icon'><div style="background-image:url('""" + getArtistImage(e["artist"],fast=True) + """')"></div></td>"""
html += "<td class='artist'>" + artistLink(e["artist"])
if (e["counting"] != []):
html += " <span class='extra'>incl. " + ", ".join([artistLink(a) for a in e["counting"]]) + "</span>"
html += "</td>"
img = getArtistImage(e["artist"],fast=True)
else: img = None
html += entity_column(e["artist"],image=img)
html += "<td class='amount'>" + scrobblesArtistLink(e["artist"],{"since":fromstr,"to":tostr},amount=e["scrobbles"],associated=True) + "</td>"
html += "<td class='bar'>" + scrobblesArtistLink(e["artist"],{"since":fromstr,"to":tostr},percent=e["scrobbles"]*100/maxbar,associated=True) + "</td>"
html += "</tr>"

View File

@ -2,11 +2,14 @@
document.addEventListener("DOMContentLoaded",function() {
document.getElementById("serverurl").addEventListener("input",updateServer);
document.getElementById("apikey").addEventListener("input",updateAPIKey);
document.getElementById("serverurl").addEventListener("change",checkServer);
document.getElementById("apikey").addEventListener("change",checkServer);
document.getElementById("serverurl").addEventListener("focusout",checkServer);
document.getElementById("apikey").addEventListener("focusout",checkServer);
chrome.storage.local.get({"serverurl":"http://localhost:42010"},function(result) {
document.getElementById("serverurl").value = result["serverurl"]
checkServer()
@ -15,18 +18,18 @@ document.addEventListener("DOMContentLoaded",function() {
document.getElementById("apikey").value = result["apikey"]
checkServer()
});
});
function updateServer() {
text = document.getElementById("serverurl").value
chrome.storage.local.set({"serverurl":text})
}
@ -37,7 +40,7 @@ function updateAPIKey() {
function checkServer() {
url = document.getElementById("serverurl").value + "/db/test?key=" + document.getElementById("apikey").value
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = createCheckmarks;
try {
@ -50,7 +53,7 @@ function checkServer() {
document.getElementById("serverurl").style.backgroundColor = "red"
document.getElementById("apikey").style.backgroundColor = "red"
}
}
function createCheckmarks() {