diff --git a/app/api/artist.py b/app/api/artist.py index 414bb6e2..be5d6ee5 100644 --- a/app/api/artist.py +++ b/app/api/artist.py @@ -221,13 +221,15 @@ def get_artist(artisthash: str): genres = list(genres) - min_stamp = min(t.date for t in tracks) - year = datetime.fromtimestamp(min_stamp).year + try: + min_stamp = min(t.date for t in tracks) + year = datetime.fromtimestamp(min_stamp).year + except ValueError: + year = 0 # TODO: Find a way to round a number to the nearest lower 10, and just add an "s" to get the decade year = int(str(year)[:3]) - decade = "" if year == 196: diff --git a/app/api/settings.py b/app/api/settings.py index 9051a0af..01973dbd 100644 --- a/app/api/settings.py +++ b/app/api/settings.py @@ -149,6 +149,7 @@ mapp = { "clean_album_title": SessionVarKeys.CLEAN_ALBUM_TITLE, "remove_remaster": SessionVarKeys.REMOVE_REMASTER_FROM_TRACK, "merge_albums": SessionVarKeys.MERGE_ALBUM_VERSIONS, + "show_albums_as_singles": SessionVarKeys.SHOW_ALBUMS_AS_SINGLES, } diff --git a/app/db/sqlite/queries.py b/app/db/sqlite/queries.py index 9fe137f5..cd7d8d9b 100644 --- a/app/db/sqlite/queries.py +++ b/app/db/sqlite/queries.py @@ -31,7 +31,8 @@ CREATE TABLE IF NOT EXISTS settings ( remove_prod integer NOT NULL DEFAULT 1, clean_album_title integer NOT NULL DEFAULT 1, remove_remaster integer NOT NULL DEFAULT 1, - merge_albums integer NOT NULL DEFAULT 0 + merge_albums integer NOT NULL DEFAULT 0, + show_albums_as_singles NOT NULL DEFAULT 0 ); CREATE TABLE IF NOT EXISTS lastfm_similar_artists ( diff --git a/app/db/sqlite/settings.py b/app/db/sqlite/settings.py index 393fe7dc..a6dce956 100644 --- a/app/db/sqlite/settings.py +++ b/app/db/sqlite/settings.py @@ -149,3 +149,4 @@ def load_settings(): SessionVars.CLEAN_ALBUM_TITLE = bool(s[3]) SessionVars.REMOVE_REMASTER_FROM_TRACK = bool(s[4]) SessionVars.MERGE_ALBUM_VERSIONS = bool(s[5]) + SessionVars.SHOW_ALBUMS_AS_SINGLES = bool(s[6]) diff --git a/app/migrations/v1_3_0/__init__.py b/app/migrations/v1_3_0/__init__.py index 27648fdd..9ae96798 100644 --- a/app/migrations/v1_3_0/__init__.py +++ b/app/migrations/v1_3_0/__init__.py @@ -296,7 +296,8 @@ class UpdateAppSettingsTable(Migration): remove_prod integer NOT NULL DEFAULT 1, clean_album_title integer NOT NULL DEFAULT 1, remove_remaster integer NOT NULL DEFAULT 1, - merge_albums integer NOT NULL DEFAULT 0 + merge_albums integer NOT NULL DEFAULT 0, + show_albums_as_singles NOT NULL DEFAULT 0 ); """ diff --git a/app/models/album.py b/app/models/album.py index 73c77a62..0f11304b 100644 --- a/app/models/album.py +++ b/app/models/album.py @@ -166,11 +166,20 @@ class Album: Checks if the album is a single. """ keywords = ["single version", "- single"] + + show_albums_as_singles = get_flag( + SessionVarKeys.SHOW_ALBUMS_AS_SINGLES + ) + for keyword in keywords: if keyword in self.title.lower(): self.is_single = True return + if show_albums_as_singles and len(tracks) == 1: + self.is_single = True + return + if ( len(tracks) == 1 and ( diff --git a/app/settings.py b/app/settings.py index 40c2cccb..dfee3a28 100644 --- a/app/settings.py +++ b/app/settings.py @@ -176,6 +176,7 @@ class SessionVars: MERGE_ALBUM_VERSIONS = False ARTIST_SEPARATORS = set() + SHOW_ALBUMS_AS_SINGLES = True # TODO: Find a way to eliminate this class without breaking typings @@ -188,6 +189,9 @@ class SessionVarKeys: PERIODIC_SCAN_INTERVAL = "PERIODIC_SCAN_INTERVAL" MERGE_ALBUM_VERSIONS = "MERGE_ALBUM_VERSIONS" ARTIST_SEPARATORS = "ARTIST_SEPARATORS" + SHOW_ALBUMS_AS_SINGLES = ( + "SHOW_ALBUMS_AS_SINGLES" + ) def get_flag(key: SessionVarKeys) -> bool: