mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
fix: remove favorite tracks whose values are None when getting favs
+ sync is_fav state when populating
This commit is contained in:
+13
-10
@@ -150,6 +150,8 @@ def get_all_favorites():
|
|||||||
favs = favdb.get_all()
|
favs = favdb.get_all()
|
||||||
favs.reverse()
|
favs.reverse()
|
||||||
|
|
||||||
|
favs = [fav for fav in favs if fav[1] != ""]
|
||||||
|
|
||||||
tracks = []
|
tracks = []
|
||||||
albums = []
|
albums = []
|
||||||
artists = []
|
artists = []
|
||||||
@@ -162,21 +164,22 @@ def get_all_favorites():
|
|||||||
):
|
):
|
||||||
break
|
break
|
||||||
|
|
||||||
if fav[2] == FavType.track:
|
if not len(tracks) >= track_limit:
|
||||||
tracks.append(fav[1])
|
if fav[2] == FavType.track:
|
||||||
elif fav[2] == FavType.album:
|
tracks.append(fav[1])
|
||||||
albums.append(fav[1])
|
|
||||||
elif fav[2] == FavType.artist:
|
if not len(albums) >= album_limit:
|
||||||
artists.append(fav[1])
|
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_tracks = sorted(Store.tracks, key=lambda x: x.trackhash)
|
||||||
src_albums = sorted(Store.albums, key=lambda x: x.albumhash)
|
src_albums = sorted(Store.albums, key=lambda x: x.albumhash)
|
||||||
src_artists = sorted(Store.artists, key=lambda x: x.artisthash)
|
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)()
|
tracks = UseBisection(src_tracks, "trackhash", tracks)()
|
||||||
albums = UseBisection(src_albums, "albumhash", albums)()
|
albums = UseBisection(src_albums, "albumhash", albums)()
|
||||||
artists = UseBisection(src_artists, "artisthash", artists)()
|
artists = UseBisection(src_artists, "artisthash", artists)()
|
||||||
|
|||||||
@@ -166,7 +166,6 @@ def update_playlist_info(playlistid: str):
|
|||||||
return {"error": "Failed: Invalid image"}, 400
|
return {"error": "Failed: Invalid image"}, 400
|
||||||
|
|
||||||
p_tuple = (*playlist.values(),)
|
p_tuple = (*playlist.values(),)
|
||||||
print("banner pos:", playlist["banner_pos"])
|
|
||||||
|
|
||||||
update_playlist(int(playlistid), playlist)
|
update_playlist(int(playlistid), playlist)
|
||||||
|
|
||||||
|
|||||||
+8
-6
@@ -57,18 +57,19 @@ def add_root_dirs():
|
|||||||
|
|
||||||
# ---
|
# ---
|
||||||
db_dirs = sdb.get_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!"}
|
return {"msg": "Not changed!"}
|
||||||
|
|
||||||
if db_dirs[0] == "$home":
|
if db_dirs[0] == _h:
|
||||||
sdb.remove_root_dirs(db_dirs)
|
sdb.remove_root_dirs(db_dirs)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if new_dirs[0] == "$home":
|
if new_dirs[0] == _h:
|
||||||
finalize(["$home"], db_dirs, [settings.USER_HOME_DIR])
|
finalize([_h], db_dirs, [settings.USER_HOME_DIR])
|
||||||
|
|
||||||
return {"msg": "Updated!"}
|
return {"root_dirs": [_h]}
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -84,10 +85,11 @@ def add_root_dirs():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
db_dirs.extend(new_dirs)
|
db_dirs.extend(new_dirs)
|
||||||
|
db_dirs = [dir for dir in db_dirs if dir != _h]
|
||||||
|
|
||||||
finalize(new_dirs, removed_dirs, db_dirs)
|
finalize(new_dirs, removed_dirs, db_dirs)
|
||||||
|
|
||||||
return {"msg": "Updated!"}
|
return {"root_dirs": db_dirs}
|
||||||
|
|
||||||
|
|
||||||
@api.route("/settings/get-root-dirs", methods=["GET"])
|
@api.route("/settings/get-root-dirs", methods=["GET"])
|
||||||
|
|||||||
+19
-4
@@ -4,6 +4,7 @@ Helper functions for use with the SQLite database.
|
|||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from sqlite3 import Connection, Cursor
|
from sqlite3 import Connection, Cursor
|
||||||
|
import time
|
||||||
|
|
||||||
from app.models import Album, Playlist, Track
|
from app.models import Album, Playlist, Track
|
||||||
from app.settings import APP_DB_PATH, USERDATA_DB_PATH
|
from app.settings import APP_DB_PATH, USERDATA_DB_PATH
|
||||||
@@ -82,12 +83,26 @@ class SQLiteManager:
|
|||||||
if self.userdata_db:
|
if self.userdata_db:
|
||||||
db_path = USERDATA_DB_PATH
|
db_path = USERDATA_DB_PATH
|
||||||
|
|
||||||
self.conn = sqlite3.connect(db_path)
|
self.conn = sqlite3.connect(
|
||||||
|
db_path,
|
||||||
|
timeout=15,
|
||||||
|
)
|
||||||
return self.conn.cursor()
|
return self.conn.cursor()
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, exc_traceback):
|
def __exit__(self, exc_type, exc_value, exc_traceback):
|
||||||
if self.conn:
|
if self.conn:
|
||||||
self.conn.commit()
|
trial_count = 0
|
||||||
|
|
||||||
if self.CLOSE_CONN:
|
while trial_count < 10:
|
||||||
self.conn.close()
|
try:
|
||||||
|
self.conn.commit()
|
||||||
|
|
||||||
|
if self.CLOSE_CONN:
|
||||||
|
self.conn.close()
|
||||||
|
|
||||||
|
return
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
trial_count += 1
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
|
self.conn.close()
|
||||||
|
|||||||
+1
-2
@@ -40,7 +40,7 @@ class Store:
|
|||||||
cls.tracks = list(tdb.get_all_tracks())
|
cls.tracks = list(tdb.get_all_tracks())
|
||||||
|
|
||||||
fav_hashes = favdb.get_fav_tracks()
|
fav_hashes = favdb.get_fav_tracks()
|
||||||
fav_hashes = [t[1] for t in fav_hashes]
|
fav_hashes = " ".join([t[1] for t in fav_hashes])
|
||||||
|
|
||||||
for track in tqdm(cls.tracks, desc="Loading tracks"):
|
for track in tqdm(cls.tracks, desc="Loading tracks"):
|
||||||
if track.trackhash in fav_hashes:
|
if track.trackhash in fav_hashes:
|
||||||
@@ -225,7 +225,6 @@ class Store:
|
|||||||
|
|
||||||
cls.folders.append(folder)
|
cls.folders.append(folder)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_folder(cls, path: str): # type: ignore
|
def get_folder(cls, path: str): # type: ignore
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from tqdm import tqdm
|
|||||||
from app import settings
|
from app import settings
|
||||||
from app.db.sqlite.tracks import SQLiteTrackMethods
|
from app.db.sqlite.tracks import SQLiteTrackMethods
|
||||||
from app.db.sqlite.settings import SettingsSQLMethods as sdb
|
from app.db.sqlite.settings import SettingsSQLMethods as sdb
|
||||||
|
from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb
|
||||||
from app.db.store import Store
|
from app.db.store import Store
|
||||||
|
|
||||||
from app.lib.taglib import extract_thumb, get_tags
|
from app.lib.taglib import extract_thumb, get_tags
|
||||||
@@ -101,12 +102,16 @@ class Populate:
|
|||||||
tagged_tracks: list[dict] = []
|
tagged_tracks: list[dict] = []
|
||||||
tagged_count = 0
|
tagged_count = 0
|
||||||
|
|
||||||
|
fav_tracks = favdb.get_fav_tracks()
|
||||||
|
fav_tracks = "-".join([t[1] for t in fav_tracks])
|
||||||
|
|
||||||
for file in tqdm(untagged, desc="Reading files"):
|
for file in tqdm(untagged, desc="Reading files"):
|
||||||
tags = get_tags(file)
|
tags = get_tags(file)
|
||||||
|
|
||||||
if tags is not None:
|
if tags is not None:
|
||||||
tagged_tracks.append(tags)
|
tagged_tracks.append(tags)
|
||||||
track = Track(**tags)
|
track = Track(**tags)
|
||||||
|
track.is_favorite = track.trackhash in fav_tracks
|
||||||
|
|
||||||
Store.add_track(track)
|
Store.add_track(track)
|
||||||
Store.add_folder(track.folder)
|
Store.add_folder(track.folder)
|
||||||
|
|||||||
Reference in New Issue
Block a user