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

Fixed API bug and added track certifications

This commit is contained in:
Krateng 2019-06-13 11:37:42 +02:00
parent 060cb7ea23
commit 746475390f
3 changed files with 31 additions and 7 deletions

View File

@ -511,14 +511,16 @@ def artistInfo_external(**keys):
def artistInfo(artist): def artistInfo(artist):
charts = db_aggregate(by="ARTIST") charts = db_aggregate(by="ARTIST")
scrobbles = len(db_query(artists=[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: try:
c = [e for e in charts if e["artist"] == artist][0] c = [e for e in charts if e["artist"] == artist][0]
others = [a for a in coa.getAllAssociated(artist) if a in ARTISTS] others = [a for a in coa.getAllAssociated(artist) if a in ARTISTS]
position = c["rank"] position = c["rank"]
return {"scrobbles":scrobbles,"position":position,"associated":others,"medals":MEDALS.get(artist)} return {"scrobbles":scrobbles,"position":position,"associated":others,"medals":MEDALS.get(artist)}
except: except:
# if the artist isnt in the charts, they are not being credited and we need to show information about the credited one # if the artist isnt in the charts, they are not being credited and we
# need to show information about the credited one
artist = coa.getCredited(artist) artist = coa.getCredited(artist)
c = [e for e in charts if e["artist"] == artist][0] c = [e for e in charts if e["artist"] == artist][0]
position = c["rank"] position = c["rank"]
@ -529,21 +531,36 @@ def artistInfo(artist):
@dbserver.get("trackinfo") @dbserver.get("trackinfo")
def trackInfo_external(**keys): def trackInfo_external(artist:Multi[str],**keys):
# transform into a multidict so we can use our nomral uri_to_internal function
keys = FormsDict(keys)
for a in artist:
keys.append("artist",a)
k_filter, _, _, _ = uri_to_internal(keys,forceTrack=True) k_filter, _, _, _ = uri_to_internal(keys,forceTrack=True)
ckeys = {**k_filter} ckeys = {**k_filter}
results = trackInfo(**ckeys) results = trackInfo(**ckeys)
return results return results
def trackInfo(artists,title): def trackInfo(track):
charts = db_aggregate(by="TRACK") charts = db_aggregate(by="TRACK")
#scrobbles = len(db_query(artists=artists,title=title)) #chart entry of track always has right scrobble number, no countas rules here #scrobbles = len(db_query(artists=artists,title=title)) #chart entry of track always has right scrobble number, no countas rules here
c = [e for e in charts if set(e["track"]["artists"]) == set(artists) and e["track"]["title"] == title][0] #c = [e for e in charts if set(e["track"]["artists"]) == set(artists) and e["track"]["title"] == title][0]
c = [e for e in charts if e["track"] == track][0]
scrobbles = c["scrobbles"] scrobbles = c["scrobbles"]
position = c["rank"] position = c["rank"]
cert = None
threshold_gold, threshold_platinum, threshold_diamond = settings.get_settings("SCROBBLES_GOLD","SCROBBLES_PLATINUM","SCROBBLES_PLATINUM")
if scrobbles >= threshold_diamond: cert = "diamond"
elif scrobbles >= threshold_platinum: cert = "platinum"
elif scrobbles >= threshold_gold: cert = "gold"
return {"scrobbles":scrobbles,"position":position,"medals":MEDALS_TRACKS.get((frozenset(artists),title))} return {
"scrobbles":scrobbles,
"position":position,
"medals":MEDALS_TRACKS.get((frozenset(track["artists"]),track["title"])),
"certification":cert
}

View File

@ -30,6 +30,13 @@ DEFAULT_RANGE_CHARTS_TRACKS = year
# can be days, weeks, months, years # can be days, weeks, months, years
DEFAULT_RANGE_PULSE = months DEFAULT_RANGE_PULSE = months
[Fluff]
# how many scrobbles a track needs to aquire this status
SCROBBLES_GOLD = 250
SCROBBLES_PLATINUM = 500
SCROBBLES_DIAMOND = 1000
[Misc] [Misc]
EXPERIMENTAL_FEATURES = no EXPERIMENTAL_FEATURES = no

View File

@ -16,7 +16,7 @@ def instructions(keys):
imgurl = getTrackImage(track["artists"],track["title"],fast=True) imgurl = getTrackImage(track["artists"],track["title"],fast=True)
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
data = database.trackInfo(track["artists"],track["title"]) data = database.trackInfo(track)
scrobblesnum = str(data["scrobbles"]) scrobblesnum = str(data["scrobbles"])
pos = "#" + str(data["position"]) pos = "#" + str(data["position"])