Various fixes

This commit is contained in:
krateng 2023-10-26 23:33:43 +02:00
parent 6de866670e
commit f7c4b260b0
4 changed files with 38 additions and 28 deletions

View File

@ -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
}

View File

@ -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,

View File

@ -7,7 +7,7 @@
<div id="showcase_container">
{% for album in ownalbums %}
{% set info = dbc.album_info({'album':album}) %}
{% set info = dbc.album_info({'album':album,'reduced':True}) %}
<table class="album">
<tr><td>&nbsp</td></tr>
<tr><td>
@ -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}) %}
<table class="album">
<tr><td>Appears on</td></tr>
<tr><td>

View File

@ -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);