diff --git a/database.py b/database.py index 34e64ce..e56dee5 100644 --- a/database.py +++ b/database.py @@ -511,14 +511,16 @@ def artistInfo_external(**keys): def artistInfo(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: c = [e for e in charts if e["artist"] == artist][0] others = [a for a in coa.getAllAssociated(artist) if a in ARTISTS] position = c["rank"] return {"scrobbles":scrobbles,"position":position,"associated":others,"medals":MEDALS.get(artist)} 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) c = [e for e in charts if e["artist"] == artist][0] position = c["rank"] @@ -529,21 +531,36 @@ def artistInfo(artist): @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) ckeys = {**k_filter} results = trackInfo(**ckeys) return results -def trackInfo(artists,title): +def trackInfo(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 - 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"] 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 + } diff --git a/settings/default.ini b/settings/default.ini index 67a11e2..b6661ab 100644 --- a/settings/default.ini +++ b/settings/default.ini @@ -30,6 +30,13 @@ DEFAULT_RANGE_CHARTS_TRACKS = year # can be days, weeks, months, years 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] EXPERIMENTAL_FEATURES = no diff --git a/website/track.py b/website/track.py index 25dafc5..b114ce2 100644 --- a/website/track.py +++ b/website/track.py @@ -16,7 +16,7 @@ def instructions(keys): imgurl = getTrackImage(track["artists"],track["title"],fast=True) pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] - data = database.trackInfo(track["artists"],track["title"]) + data = database.trackInfo(track) scrobblesnum = str(data["scrobbles"]) pos = "#" + str(data["position"])