mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Added track view
This commit is contained in:
parent
5987997075
commit
5fd6810098
13
database.py
13
database.py
@ -344,6 +344,19 @@ def artistInfo():
|
||||
c = [e for e in charts if e["artist"] == artist][0]
|
||||
return {"replace":artist,"scrobbles":scrobbles,"position":charts.index(c) + 1}
|
||||
|
||||
@dbserver.route("/trackinfo")
|
||||
def trackInfo():
|
||||
keys = FormsDict.decode(request.query)
|
||||
artists = keys.getall("artist")
|
||||
title = keys.get("title")
|
||||
|
||||
charts = db_aggregate(by="TRACK")
|
||||
scrobbles = len(db_query(artists=artists,title=title)) #we cant take the scrobble number from the charts because that includes all countas scrobbles
|
||||
|
||||
|
||||
c = [e for e in charts if set(e["track"]["artists"]) == set(artists) and e["track"]["title"] == title][0]
|
||||
return {"scrobbles":scrobbles,"position":charts.index(c) + 1}
|
||||
|
||||
def isPast(date,limit):
|
||||
if not date[0] == limit[0]:
|
||||
return date[0] > limit[0]
|
||||
|
@ -18,12 +18,12 @@ def trackLink(track):
|
||||
def scrobblesTrackLink(track,timekeys,amount=None,percent=None):
|
||||
artists,title = track["artists"],track["title"]
|
||||
import urllib
|
||||
inner = str(amount) if amount is not None else "<div style='width:" + str(pixels) + "%;'></div>"
|
||||
inner = str(amount) if amount is not None else "<div style='width:" + str(percent) + "%;'></div>"
|
||||
return "<a href='/scrobbles?" + "&".join(["artist=" + urllib.parse.quote(a) for a in artists]) + "&title=" + urllib.parse.quote(title) + "&" + keysToUrl(timekeys) + "'>" + inner + "</a>"
|
||||
|
||||
def scrobblesArtistLink(artist,timekeys,amount=None,percent=None,associated=False):
|
||||
import urllib
|
||||
inner = str(amount) if amount is not None else "<div style='width:" + str(pixels) + "%;'></div>"
|
||||
inner = str(amount) if amount is not None else "<div style='width:" + str(percent) + "%;'></div>"
|
||||
askey = "&associated" if associated else ""
|
||||
return "<a href='/scrobbles?artist=" + urllib.parse.quote(artist) + "&" + keysToUrl(timekeys) + askey + "'>" + inner + "</a>"
|
||||
|
||||
|
30
website/track.html
Normal file
30
website/track.html
Normal file
@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Maloja - KEY_TRACKTITLE</title>
|
||||
<link rel="stylesheet" href="maloja.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table class="top_info">
|
||||
<tr>
|
||||
<td class="image">
|
||||
<div style="background-image:url('KEY_IMAGEURL')"></div>
|
||||
</td>
|
||||
<td class="text">
|
||||
<h1>KEY_TRACKTITLE</h1> <span class="rank"><a href="/toptracks">KEY_POSITION</a></span><br/>
|
||||
<span>KEY_ARTISTS</span>
|
||||
<p class="stats"><a href="/scrobbles?KEY_SCROBBLELINK">KEY_SCROBBLES Scrobbles</a></p>
|
||||
|
||||
<p class="desc"></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><a href='/scrobbles?KEY_SCROBBLELINK'>Scrobbles</a></h2>
|
||||
KEY_SCROBBLELIST
|
||||
|
||||
</body>
|
||||
</html>
|
37
website/track.py
Normal file
37
website/track.py
Normal file
@ -0,0 +1,37 @@
|
||||
import urllib
|
||||
import json
|
||||
|
||||
|
||||
def replacedict(keys,dbport):
|
||||
from utilities import getArtistInfo
|
||||
from htmlgenerators import clean, artistLink, artistLinks, trackLink, scrobblesTrackLink, keysToUrl, pickKeys, getTimeDesc
|
||||
|
||||
clean(keys)
|
||||
limitkeys = pickKeys(keys,"artist","title")
|
||||
info = getArtistInfo(keys["artist"])
|
||||
imgurl = info.get("image")
|
||||
desc = info.get("info")
|
||||
|
||||
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/trackinfo?" + keysToUrl(limitkeys))
|
||||
db_data = json.loads(response.read())
|
||||
scrobblesnum = str(db_data["scrobbles"])
|
||||
pos = "#" + str(db_data["position"])
|
||||
|
||||
|
||||
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + keysToUrl(limitkeys))
|
||||
db_data = json.loads(response.read())
|
||||
scrobbles = db_data["list"]
|
||||
|
||||
|
||||
# build list
|
||||
html = "<table class='list'>"
|
||||
for s in scrobbles:
|
||||
html += "<tr>"
|
||||
html += "<td class='time'>" + getTimeDesc(s["time"]) + "</td>"
|
||||
html += "<td class='artists'>" + artistLinks(s["artists"]) + "</td>"
|
||||
html += "<td class='title'>" + trackLink({"artists":s["artists"],"title":s["title"]}) + "</td>"
|
||||
html += "</tr>"
|
||||
html += "</table>"
|
||||
|
||||
|
||||
return {"KEY_TRACKTITLE":limitkeys.get("title"),"KEY_ARTISTS":artistLinks(limitkeys.getall("artist")),"KEY_SCROBBLES":scrobblesnum,"KEY_IMAGEURL":imgurl,"KEY_SCROBBLELINK":keysToUrl(limitkeys),"KEY_SCROBBLELIST":html,"KEY_POSITION":pos}
|
Loading…
Reference in New Issue
Block a user