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

51 lines
1.6 KiB
Python
Raw Normal View History

2018-12-19 18:11:10 +03:00
import urllib
import database
2018-12-19 18:11:10 +03:00
def instructions(keys):
2018-12-29 02:08:00 +03:00
from utilities import getArtistInfo, getTrackInfo
from htmlgenerators import artistLink, artistLinks, trackLink, KeySplit
2019-03-03 00:55:22 +03:00
from htmlmodules import module_scrobblelist
from malojatime import range_desc
2018-12-19 18:11:10 +03:00
2018-12-27 05:09:29 +03:00
filterkeys, timekeys, _, amountkeys = KeySplit(keys)
2018-12-23 01:19:52 +03:00
2018-12-27 05:09:29 +03:00
# describe the scope
limitstring = ""
if filterkeys.get("track") is not None:
limitstring += "of " + trackLink(filterkeys["track"]) + " "
limitstring += "by " + artistLinks(filterkeys["track"]["artists"])
elif filterkeys.get("artist") is not None:
limitstring += "by " + artistLink(filterkeys.get("artist"))
if filterkeys.get("associated"):
data = database.artistInfo(filterkeys["artist"])
moreartists = data.get("associated")
2018-12-23 01:19:52 +03:00
if moreartists != []:
2018-12-27 05:09:29 +03:00
limitstring += " <span class='extra'>including " + artistLinks(moreartists) + "</span>"
2018-12-23 01:19:52 +03:00
2019-03-03 00:55:22 +03:00
limitstring += " " + range_desc(**timekeys)
html, amount, rep = module_scrobblelist(**filterkeys,**timekeys,**amountkeys)
2018-12-27 05:09:29 +03:00
2018-12-29 02:08:00 +03:00
# get image
if filterkeys.get("track") is not None:
imgurl = getTrackInfo(filterkeys.get("track")["artists"],filterkeys.get("track")["title"]).get("image")
elif filterkeys.get("artist") is not None:
2018-12-27 05:09:29 +03:00
imgurl = getArtistInfo(keys.get("artist")).get("image")
elif rep is not None:
imgurl = getTrackInfo(rep["artists"],rep["title"]).get("image")
2018-12-23 01:19:52 +03:00
else:
2018-12-27 05:09:29 +03:00
imgurl = ""
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
2018-12-23 01:19:52 +03:00
replace = {"KEY_SCROBBLELIST":html,"KEY_SCROBBLES":str(amount),"KEY_IMAGEURL":imgurl,"KEY_LIMITS":limitstring}
return (replace,pushresources)
2018-12-19 18:11:10 +03:00