check if track exists in db before sending file

This commit is contained in:
mungai-njoroge
2023-06-19 21:49:13 +03:00
parent a201303bd9
commit cc6552cb94
17 changed files with 96 additions and 31 deletions
+6 -1
View File
@@ -17,13 +17,17 @@ class SQLiteAlbumMethods:
"""
cur.execute(sql, (albumhash, colors))
return cur.lastrowid
lastrowid = cur.lastrowid
cur.close()
return lastrowid
@classmethod
def get_all_albums(cls):
with SQLiteManager() as cur:
cur.execute("SELECT * FROM albums")
albums = cur.fetchall()
cur.close()
if albums is not None:
return albums
@@ -35,6 +39,7 @@ class SQLiteAlbumMethods:
with SQLiteManager() as cur:
cur.execute("SELECT * FROM albums WHERE albumartist=?", (albumartist,))
albums = cur.fetchall()
cur.close()
if albums is not None:
return tuples_to_albums(albums)
+3
View File
@@ -21,6 +21,7 @@ class SQLiteArtistMethods:
"""
colors = json.dumps(colors)
cur.execute(sql, (artisthash, colors))
cur.close()
@staticmethod
def get_all_artists():
@@ -34,3 +35,5 @@ class SQLiteArtistMethods:
for artist in cur.fetchall():
yield artist
cur.close()
+7 -1
View File
@@ -14,6 +14,7 @@ class SQLiteFavoriteMethods:
with SQLiteManager(userdata_db=True) as cur:
cur.execute(sql, (itemhash, fav_type))
items = cur.fetchall()
cur.close()
return len(items) > 0
@classmethod
@@ -28,6 +29,7 @@ class SQLiteFavoriteMethods:
sql = """INSERT INTO favorites(type, hash) VALUES(?,?)"""
with SQLiteManager(userdata_db=True) as cur:
cur.execute(sql, (fav_type, fav_hash))
cur.close()
@classmethod
def get_all(cls) -> list[tuple]:
@@ -38,6 +40,7 @@ class SQLiteFavoriteMethods:
with SQLiteManager(userdata_db=True) as cur:
cur.execute(sql)
favs = cur.fetchall()
cur.close()
return [fav for fav in favs if fav[1] != ""]
@classmethod
@@ -48,7 +51,9 @@ class SQLiteFavoriteMethods:
sql = """SELECT * FROM favorites WHERE type = ?"""
with SQLiteManager(userdata_db=True) as cur:
cur.execute(sql, (fav_type,))
return cur.fetchall()
all_favs = cur.fetchall()
cur.close()
return all_favs
@classmethod
def get_fav_tracks(cls) -> list[tuple]:
@@ -80,3 +85,4 @@ class SQLiteFavoriteMethods:
with SQLiteManager(userdata_db=True) as cur:
cur.execute(sql, (fav_hash, fav_type))
cur.close()
+13 -3
View File
@@ -21,7 +21,10 @@ class MigrationManager:
"""
with SQLiteManager() as cur:
cur.execute(cls.all_get_sql)
return int(cur.fetchone()[1])
ver = int(cur.fetchone()[1])
cur.close()
return ver
@classmethod
def get_maindb_postinit_version(cls) -> int:
@@ -30,7 +33,10 @@ class MigrationManager:
"""
with SQLiteManager() as cur:
cur.execute(cls.all_get_sql)
return int(cur.fetchone()[2])
ver = int(cur.fetchone()[2])
cur.close()
return ver
@classmethod
def get_userdatadb_postinit_version(cls) -> int:
@@ -39,7 +45,10 @@ class MigrationManager:
"""
with SQLiteManager(userdata_db=True) as cur:
cur.execute(cls.all_get_sql)
return cur.fetchone()[2]
ver = cur.fetchone()[2]
cur.close()
return ver
# 👇 Setters 👇
@classmethod
@@ -49,6 +58,7 @@ class MigrationManager:
"""
with SQLiteManager() as cur:
cur.execute(cls.pre_init_set_sql, (version,))
cur.close()
@classmethod
def set_maindb_postinit_version(cls, version: int):
+5
View File
@@ -31,6 +31,7 @@ class SQLitePlaylistMethods:
with SQLiteManager(userdata_db=True) as cur:
cur.execute(sql, playlist)
pid = cur.lastrowid
cur.close()
p_tuple = (pid, *playlist.values())
return tuple_to_playlist(p_tuple)
@@ -43,6 +44,7 @@ class SQLitePlaylistMethods:
cur.execute(sql, (name,))
data = cur.fetchone()
cur.close()
if data is not None:
return tuple_to_playlist(data)
@@ -57,6 +59,7 @@ class SQLitePlaylistMethods:
cur.execute(sql, (name,))
data = cur.fetchone()
cur.close()
return int(data[0])
@@ -65,6 +68,7 @@ class SQLitePlaylistMethods:
with SQLiteManager(userdata_db=True) as cur:
cur.execute("SELECT * FROM playlists")
playlists = cur.fetchall()
cur.close()
if playlists is not None:
return tuples_to_playlists(playlists)
@@ -79,6 +83,7 @@ class SQLitePlaylistMethods:
cur.execute(sql, (playlist_id,))
data = cur.fetchone()
cur.close()
if data is not None:
return tuple_to_playlist(data)
+1
View File
@@ -18,6 +18,7 @@ class SettingsSQLMethods:
with SQLiteManager(userdata_db=True) as cur:
cur.execute(sql)
dirs = cur.fetchall()
cur.close()
dirs = [_dir[0] for _dir in dirs]
return [win_replace_slash(d) for d in dirs]