diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index c37ef8e..fc6bf2b 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -727,7 +727,7 @@ def track_info(dbconn=None,**keys): @waitfordb -def album_info(dbconn=None,**keys): +def album_info(dbconn=None,reduced=False,**keys): album = keys.get('album') if album is None: raise exceptions.MissingEntityParameter() @@ -751,35 +751,41 @@ def album_info(dbconn=None,**keys): elif scrobbles >= threshold_platinum: cert = "platinum" elif scrobbles >= threshold_gold: cert = "gold" - twk = thisweek() - tyr = thisyear() + if reduced: + extrainfo = {} + else: + twk = thisweek() + tyr = thisyear() + extrainfo = { + "medals":{ + "gold": [year.desc() for year in ranges(step='year') if (year != tyr) and any( + (e.get('album_id') == album_id) and (e.get('rank') == 1) for e in + sqldb.count_scrobbles_by_album(since=year.first_stamp(),to=year.last_stamp(),resolve_ids=False,dbconn=dbconn) + )], + "silver": [year.desc() for year in ranges(step='year') if (year != tyr) and any( + (e.get('album_id') == album_id) and (e.get('rank') == 2) for e in + sqldb.count_scrobbles_by_album(since=year.first_stamp(),to=year.last_stamp(),resolve_ids=False,dbconn=dbconn) + )], + "bronze": [year.desc() for year in ranges(step='year') if (year != tyr) and any( + (e.get('album_id') == album_id) and (e.get('rank') == 3) for e in + sqldb.count_scrobbles_by_album(since=year.first_stamp(),to=year.last_stamp(),resolve_ids=False,dbconn=dbconn) + )] + }, + "topweeks":len([ + week for week in ranges(step="week") if (week != twk) and any( + (e.get('album_id') == album_id) and (e.get('rank') == 1) for e in + sqldb.count_scrobbles_by_album(since=week.first_stamp(),to=week.last_stamp(),resolve_ids=False,dbconn=dbconn) + ) + ]) + } return { "album":album, "scrobbles":scrobbles, "position":position, - "medals":{ - "gold": [year.desc() for year in ranges(step='year') if (year != tyr) and any( - (e.get('album_id') == album_id) and (e.get('rank') == 1) for e in - sqldb.count_scrobbles_by_album(since=year.first_stamp(),to=year.last_stamp(),resolve_ids=False,dbconn=dbconn) - )], - "silver": [year.desc() for year in ranges(step='year') if (year != tyr) and any( - (e.get('album_id') == album_id) and (e.get('rank') == 2) for e in - sqldb.count_scrobbles_by_album(since=year.first_stamp(),to=year.last_stamp(),resolve_ids=False,dbconn=dbconn) - )], - "bronze": [year.desc() for year in ranges(step='year') if (year != tyr) and any( - (e.get('album_id') == album_id) and (e.get('rank') == 3) for e in - sqldb.count_scrobbles_by_album(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('album_id') == album_id) and (e.get('rank') == 1) for e in - sqldb.count_scrobbles_by_album(since=week.first_stamp(),to=week.last_stamp(),resolve_ids=False,dbconn=dbconn) - ) - ]), - "id":album_id + "id":album_id, + **extrainfo } diff --git a/maloja/proccontrol/tasks/import_scrobbles.py b/maloja/proccontrol/tasks/import_scrobbles.py index 32221bc..6d22e42 100644 --- a/maloja/proccontrol/tasks/import_scrobbles.py +++ b/maloja/proccontrol/tasks/import_scrobbles.py @@ -49,7 +49,7 @@ def import_scrobbles(inputf): typeid,typedesc = "spotify","Spotify" importfunc = parse_spotify_lite_legacy - elif re.match(r"maloja_export_[0-9]+\.json",filename): + elif re.match(r"maloja_export_?[0-9]*\.json",filename): typeid,typedesc = "maloja","Maloja" importfunc = parse_maloja @@ -99,7 +99,7 @@ def import_scrobbles(inputf): "albumtitle":scrobble.get('album_name') or None, "artists":scrobble.get('album_artists') or scrobble['track_artists'] or None # TODO: use same heuristics as with parsing to determine album? - } + } if scrobble.get('album_name') else None }, "duration":scrobble['scrobble_duration'], "origin":"import:" + typeid, diff --git a/maloja/web/jinja/partials/album_showcase.jinja b/maloja/web/jinja/partials/album_showcase.jinja index 451ce25..e4a3d5f 100644 --- a/maloja/web/jinja/partials/album_showcase.jinja +++ b/maloja/web/jinja/partials/album_showcase.jinja @@ -7,7 +7,7 @@
{% for album in ownalbums %} -{% set info = dbc.album_info({'album':album}) %} +{% set info = dbc.album_info({'album':album,'reduced':True}) %}
 
@@ -24,7 +24,7 @@ {% endfor %} {% for album in otheralbums %} -{% set info = dbc.album_info({'album':album}) %} +{% set info = dbc.album_info({'album':album,'reduced':True}) %}
Appears on
diff --git a/maloja/web/static/css/maloja.css b/maloja/web/static/css/maloja.css index fb5204a..396091a 100644 --- a/maloja/web/static/css/maloja.css +++ b/maloja/web/static/css/maloja.css @@ -42,6 +42,10 @@ body.certified { .certified_gold { --certification-color: var(--color-certified-gold); } +.certified_None { + --certification-color: none; + /* overwrite this for non-certified elements on certified pages (albums of artist) */ +} .certified.smallcerticon svg { fill: rgba(var(--certification-color),1);