fix: remove favorite tracks whose values are None when getting favs

+ sync is_fav state when populating
This commit is contained in:
geoffrey45
2023-01-24 02:10:58 +03:00
parent 22fa3eef40
commit 29e61b31c3
6 changed files with 46 additions and 23 deletions
+13 -10
View File
@@ -150,6 +150,8 @@ def get_all_favorites():
favs = favdb.get_all()
favs.reverse()
favs = [fav for fav in favs if fav[1] != ""]
tracks = []
albums = []
artists = []
@@ -162,21 +164,22 @@ def get_all_favorites():
):
break
if fav[2] == FavType.track:
tracks.append(fav[1])
elif fav[2] == FavType.album:
albums.append(fav[1])
elif fav[2] == FavType.artist:
artists.append(fav[1])
if not len(tracks) >= track_limit:
if fav[2] == FavType.track:
tracks.append(fav[1])
if not len(albums) >= album_limit:
if fav[2] == FavType.album:
albums.append(fav[1])
if not len(artists) >= artist_limit:
if fav[2] == FavType.artist:
artists.append(fav[1])
src_tracks = sorted(Store.tracks, key=lambda x: x.trackhash)
src_albums = sorted(Store.albums, key=lambda x: x.albumhash)
src_artists = sorted(Store.artists, key=lambda x: x.artisthash)
tracks = tracks[:track_limit]
albums = albums[:album_limit]
artists = artists[:artist_limit]
tracks = UseBisection(src_tracks, "trackhash", tracks)()
albums = UseBisection(src_albums, "albumhash", albums)()
artists = UseBisection(src_artists, "artisthash", artists)()
-1
View File
@@ -166,7 +166,6 @@ def update_playlist_info(playlistid: str):
return {"error": "Failed: Invalid image"}, 400
p_tuple = (*playlist.values(),)
print("banner pos:", playlist["banner_pos"])
update_playlist(int(playlistid), playlist)
+8 -6
View File
@@ -57,18 +57,19 @@ def add_root_dirs():
# ---
db_dirs = sdb.get_root_dirs()
_h = "$home"
if db_dirs[0] == "$home" and new_dirs[0] == "$home".strip():
if db_dirs[0] == _h and new_dirs[0] == _h.strip():
return {"msg": "Not changed!"}
if db_dirs[0] == "$home":
if db_dirs[0] == _h:
sdb.remove_root_dirs(db_dirs)
try:
if new_dirs[0] == "$home":
finalize(["$home"], db_dirs, [settings.USER_HOME_DIR])
if new_dirs[0] == _h:
finalize([_h], db_dirs, [settings.USER_HOME_DIR])
return {"msg": "Updated!"}
return {"root_dirs": [_h]}
except IndexError:
pass
@@ -84,10 +85,11 @@ def add_root_dirs():
pass
db_dirs.extend(new_dirs)
db_dirs = [dir for dir in db_dirs if dir != _h]
finalize(new_dirs, removed_dirs, db_dirs)
return {"msg": "Updated!"}
return {"root_dirs": db_dirs}
@api.route("/settings/get-root-dirs", methods=["GET"])