From 4d1f810e9213fde98da035d10588a9ecbfa2a9de Mon Sep 17 00:00:00 2001 From: krateng Date: Tue, 28 Mar 2023 21:48:44 +0200 Subject: [PATCH] Improved support for artistless albums --- maloja/database/__init__.py | 3 ++- maloja/database/sqldb.py | 4 ++-- maloja/images.py | 2 +- maloja/malojauri.py | 4 ++-- maloja/pkg_global/conf.py | 1 + maloja/web/jinja/partials/charts_albums.jinja | 6 +++--- maloja/web/jinja/snippets/links.jinja | 10 +++++++--- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 5fbd5ed..7cb3c6b 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -132,7 +132,8 @@ def rawscrobble_to_scrobbledict(rawscrobble, fix=True, client=None): scrobbleinfo = {**rawscrobble} if fix: scrobbleinfo['track_artists'],scrobbleinfo['track_title'] = cla.fullclean(scrobbleinfo['track_artists'],scrobbleinfo['track_title']) - scrobbleinfo['album_artists'] = cla.parseArtists(scrobbleinfo['album_artists']) + if scrobbleinfo.get('album_artists'): + scrobbleinfo['album_artists'] = cla.parseArtists(scrobbleinfo['album_artists']) scrobbleinfo['scrobble_time'] = scrobbleinfo.get('scrobble_time') or int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()) diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index 633fc52..b4fd2c2 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -240,7 +240,7 @@ def albums_db_to_dict(rows,dbconn=None): artists = get_artists_of_albums(set(row.id for row in rows),dbconn=dbconn) return [ { - "artists":artists[row.id], + "artists":artists.get(row.id), "albumtitle":row.albtitle, } for row in rows @@ -443,7 +443,7 @@ def get_artist_id(artistname,create_new=True,dbconn=None): @connection_provider def get_album_id(albumdict,create_new=True,dbconn=None): ntitle = normalize_name(albumdict['albumtitle']) - artist_ids = [get_artist_id(a,dbconn=dbconn) for a in albumdict['artists']] + artist_ids = [get_artist_id(a,dbconn=dbconn) for a in albumdict.get('artists') or []] artist_ids = list(set(artist_ids)) diff --git a/maloja/images.py b/maloja/images.py index f92e91f..4c2fa22 100644 --- a/maloja/images.py +++ b/maloja/images.py @@ -226,7 +226,7 @@ def get_all_possible_filenames(artist=None,track=None,album=None): title, artists = clean(track['title']), [clean(a) for a in track['artists']] superfolder = "tracks/" elif album: - title, artists = clean(album['albumtitle']), [clean(a) for a in album['artists']] + title, artists = clean(album['albumtitle']), [clean(a) for a in album.get('artists') or []] superfolder = "albums/" elif artist: artist = clean(artist) diff --git a/maloja/malojauri.py b/maloja/malojauri.py index e2675cc..350a7e4 100644 --- a/maloja/malojauri.py +++ b/maloja/malojauri.py @@ -28,7 +28,7 @@ def uri_to_internal(keys,forceTrack=False,forceArtist=False,forceAlbum=False,api filterkeys = {"artist":keys.get("artist")} if "associated" in keys: filterkeys["associated"] = True elif type == "album": - filterkeys = {"album":{"artists":keys.getall("artist"),"albumtitle":keys.get("title") or keys.get("albumtitle")}} + filterkeys = {"album":{"artists":keys.getall("artist"),"albumtitle":keys.get("albumtitle") or keys.get("title")}} else: filterkeys = {} @@ -96,7 +96,7 @@ def internal_to_uri(keys): urikeys.append("artist",a) urikeys.append("title",keys["track"]["title"]) elif "album" in keys: - for a in keys["album"]["artists"]: + for a in keys["album"].get("artists") or []: urikeys.append("artist",a) urikeys.append("albumtitle",keys["album"]["albumtitle"]) diff --git a/maloja/pkg_global/conf.py b/maloja/pkg_global/conf.py index 164cfa3..7224970 100644 --- a/maloja/pkg_global/conf.py +++ b/maloja/pkg_global/conf.py @@ -192,6 +192,7 @@ malojaconfig = Configuration( "default_step_pulse":(tp.Choice({'year':'Year','month':"Month",'week':'Week','day':'Day'}), "Default Pulse Step", "month"), "charts_display_tiles":(tp.Boolean(), "Display Chart Tiles", False), "display_art_icons":(tp.Boolean(), "Display Album/Artist Icons", True), + "default_album_artist":(tp.String(), "Default Albumartist", "Various Artists"), "discourage_cpu_heavy_stats":(tp.Boolean(), "Discourage CPU-heavy stats", False, "Prevent visitors from mindlessly clicking on CPU-heavy options. Does not actually disable them for malicious actors!"), "use_local_images":(tp.Boolean(), "Use Local Images", True), #"local_image_rotate":(tp.Integer(), "Local Image Rotate", 3600), diff --git a/maloja/web/jinja/partials/charts_albums.jinja b/maloja/web/jinja/partials/charts_albums.jinja index b6bcc0f..a779e62 100644 --- a/maloja/web/jinja/partials/charts_albums.jinja +++ b/maloja/web/jinja/partials/charts_albums.jinja @@ -14,12 +14,12 @@ {% set lastranks = {} %} {% for t in prevalbums %} - {% if lastranks.update({"|".join(t.album.artists)+"||"+t.album.albumtitle:t.rank}) %}{% endif %} + {% if lastranks.update({"|".join(t.album.artists or [])+"||"+t.album.albumtitle:t.rank}) %}{% endif %} {% endfor %} {% for t in charts %} - {% if "|".join(t.album.artists)+"||"+t.album.albumtitle in lastranks %} - {% if t.update({'last_rank':lastranks["|".join(t.album.artists)+"||"+t.album.albumtitle]}) %}{% endif %} + {% if "|".join(t.album.artists or [])+"||"+t.album.albumtitle in lastranks %} + {% if t.update({'last_rank':lastranks["|".join(t.album.artists or [])+"||"+t.album.albumtitle]}) %}{% endif %} {% endif %} {% endfor %} {% endif %} diff --git a/maloja/web/jinja/snippets/links.jinja b/maloja/web/jinja/snippets/links.jinja index 280ed75..3b5c29d 100644 --- a/maloja/web/jinja/snippets/links.jinja +++ b/maloja/web/jinja/snippets/links.jinja @@ -9,9 +9,13 @@ {%- endmacro %} {% macro links(entities) -%} - {% for entity in entities -%} - {{ link(entity) }}{{ ", " if not loop.last }} - {%- endfor %} + {% if entities is none or entities == [] %} + {{ settings["DEFAULT_ALBUM_ARTIST"] }} + {% else %} + {% for entity in entities -%} + {{ link(entity) }}{{ ", " if not loop.last }} + {%- endfor %} + {% endif %} {%- endmacro %}