From 0e311e0ac80f98959df1c079134849cb89e6af86 Mon Sep 17 00:00:00 2001 From: krateng Date: Thu, 26 Oct 2023 19:47:43 +0200 Subject: [PATCH] Artists can now be pseudo-certified via their tracks or albums --- maloja/database/__init__.py | 19 +++++++++++++++++++ maloja/web/jinja/artist.jinja | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 89bfe06..c37ef8e 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -597,6 +597,24 @@ def artist_info(dbconn=None,**keys): albums = sqldb.get_albums_of_artists(set([artist_id]),dbconn=dbconn) isalbumartist = len(albums.get(artist_id,[]))>0 + cert = None + own_track_charts = get_charts_tracks(timerange=alltime(),resolve_ids=False,artist=artist,dbconn=dbconn) + own_album_charts = get_charts_albums(timerange=alltime(),resolve_ids=False,artist=artist,dbconn=dbconn) + if own_track_charts: + c = own_track_charts[0] + scrobbles = c["scrobbles"] + threshold_gold, threshold_platinum, threshold_diamond = malojaconfig["SCROBBLES_GOLD","SCROBBLES_PLATINUM","SCROBBLES_DIAMOND"] + if scrobbles >= threshold_diamond: cert = "diamond" + elif scrobbles >= threshold_platinum: cert = "platinum" + elif scrobbles >= threshold_gold: cert = "gold" + if own_album_charts: + c = own_album_charts[0] + scrobbles = c["scrobbles"] + threshold_gold, threshold_platinum, threshold_diamond = malojaconfig["SCROBBLES_GOLD_ALBUM","SCROBBLES_PLATINUM_ALBUM","SCROBBLES_DIAMOND_ALBUM"] + if scrobbles >= threshold_diamond: cert = "diamond" + elif scrobbles >= threshold_platinum and cert != "diamond": cert = "platinum" + elif scrobbles >= threshold_gold and not cert: cert = "gold" + twk = thisweek() tyr = thisyear() @@ -631,6 +649,7 @@ def artist_info(dbconn=None,**keys): sqldb.count_scrobbles_by_artist(since=year.first_stamp(),to=year.last_stamp(),resolve_ids=False,dbconn=dbconn) )] }, + "certification":cert, "topweeks":len([ week for week in ranges(step="week") if (week != twk) and any( (e.get('artist_id') == artist_id) and (e.get('rank') == 1) for e in diff --git a/maloja/web/jinja/artist.jinja b/maloja/web/jinja/artist.jinja index 5cf2d02..cffe787 100644 --- a/maloja/web/jinja/artist.jinja +++ b/maloja/web/jinja/artist.jinja @@ -26,6 +26,10 @@ {% set encodedartist = mlj_uri.uriencode({'artist':artist}) %} +{% block custombodyclasses %} + {% if info.certification %}certified certified_{{ info.certification }}{% endif %} +{% endblock %} + {% block icon_bar %} {% if adminmode %} {% include 'icons/edit.jinja' %}