From 1cf5d38a960d54e9bc5d7cbd6c3cb6cf55448e97 Mon Sep 17 00:00:00 2001 From: mungai-njoroge Date: Mon, 26 Jun 2023 13:17:24 +0300 Subject: [PATCH] fix duplicate albums with date = 0 --- app/api/artist.py | 3 +++ app/lib/watchdogg.py | 6 +++--- app/store/artists.py | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/api/artist.py b/app/api/artist.py index 6cc1580..efe180c 100644 --- a/app/api/artist.py +++ b/app/api/artist.py @@ -262,6 +262,9 @@ def get_artist_albums(artisthash: str): artist = ArtistStore.get_artist_by_hash(artisthash) + if artist is None: + return {"error": "Artist not found"}, 404 + if return_all is not None: limit = len(all_albums) diff --git a/app/lib/watchdogg.py b/app/lib/watchdogg.py index a19e615..0acea0e 100644 --- a/app/lib/watchdogg.py +++ b/app/lib/watchdogg.py @@ -129,13 +129,13 @@ def add_track(filepath: str) -> None: Then creates the folder, album and artist objects for the added track and adds them to the store. """ - # remove the track if it already exists + TrackStore.remove_track_by_filepath(filepath) - # add the track to the database and store. tags = get_tags(filepath) - if tags is None: + # if the track is somehow invalid, return + if tags is None or tags["bitrate"] == 0 or tags["duration"] == 0: return with SQLiteManager() as cur: diff --git a/app/store/artists.py b/app/store/artists.py index e24bfcc..1f3a748 100644 --- a/app/store/artists.py +++ b/app/store/artists.py @@ -61,8 +61,11 @@ class ArtistStore: Returns an artist by its hash.P """ artists = sorted(cls.artists, key=lambda x: x.artisthash) - artist = UseBisection(artists, "artisthash", [artisthash])()[0] - return artist + try: + artist = UseBisection(artists, "artisthash", [artisthash])()[0] + return artist + except IndexError: + return None @classmethod def get_artists_by_hashes(cls, artisthashes: list[str]) -> list[Artist]: