From 7f87cde96c4708cdcc5dc2b5ef089d652777fce6 Mon Sep 17 00:00:00 2001 From: mungai-njoroge Date: Wed, 6 Dec 2023 11:12:27 +0300 Subject: [PATCH] add favs count to fetch endpoint + remove filetype from track --- app/api/favorites.py | 42 +++++++++++++++++++++++++++++++--- app/lib/home/recentlyplayed.py | 3 +++ app/lib/taglib.py | 1 - 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/api/favorites.py b/app/api/favorites.py index 0c6f35d..adcfc0b 100644 --- a/app/api/favorites.py +++ b/app/api/favorites.py @@ -158,11 +158,26 @@ def get_all_favorites(): favs = favdb.get_all() favs.reverse() + count = { + "tracks": 0, + "albums": 0, + "artists": 0, + } + tracks = [] albums = [] artists = [] for fav in favs: + if fav[2] == FavType.track: + count["tracks"] += 1 + + if fav[2] == FavType.album: + count["albums"] += 1 + + if fav[2] == FavType.artist: + count["artists"] += 1 + if not len(tracks) >= largest: if fav[2] == FavType.track: tracks.append(fav[1]) @@ -198,7 +213,16 @@ def get_all_favorites(): if album is None: continue - recents.append({"type": "album", "item": serialize_for_card(album)}) + + album = serialize_for_card(album) + album["help_text"] = "album" + + recents.append( + { + "type": "album", + "item": album, + } + ) if fav[2] == FavType.artist: artist = next((a for a in artists if a.artisthash == fav[1]), None) @@ -206,7 +230,15 @@ def get_all_favorites(): if artist is None: continue - recents.append({"type": "artist", "item": serialize_artist(artist)}) + artist = serialize_artist(artist) + artist["help_text"] = "artist" + + recents.append( + { + "type": "artist", + "item": artist, + } + ) if fav[2] == FavType.track: track = next((t for t in tracks if t.trackhash == fav[1]), None) @@ -214,13 +246,17 @@ def get_all_favorites(): if track is None: continue - recents.append({"type": "track", "item": serialize_track(track)}) + track = serialize_track(track) + track["help_text"] = "track" + + recents.append({"type": "track", "item": track}) return { "recents": recents[:album_limit], "tracks": tracks[:track_limit], "albums": albums[:album_limit], "artists": artists[:artist_limit], + "count": count, } diff --git a/app/lib/home/recentlyplayed.py b/app/lib/home/recentlyplayed.py index 99156c9..0f8d871 100644 --- a/app/lib/home/recentlyplayed.py +++ b/app/lib/home/recentlyplayed.py @@ -78,6 +78,9 @@ def get_recently_played(limit=7): if entry.type == "folder": folder = entry.type_src + if not folder: + continue + is_home_dir = entry.type_src == "$home" if is_home_dir: diff --git a/app/lib/taglib.py b/app/lib/taglib.py index 05c227d..63fd4d7 100644 --- a/app/lib/taglib.py +++ b/app/lib/taglib.py @@ -213,7 +213,6 @@ def get_tags(filepath: str): tags.date = parse_date(tags.year) or int(last_mod) tags.filepath = win_replace_slash(filepath) - tags.filetype = filetype tags.last_mod = last_mod tags.artists = tags.artist