mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
fix duplicate artist and album color entry in db
+ Remove folder store + Reduce fuzzy search score cutoff from 90% to 75% + use inheritance to init Artist class + misc
This commit is contained in:
+2
-83
@@ -1,6 +1,6 @@
|
||||
from sqlite3 import Cursor
|
||||
|
||||
from .utils import SQLiteManager, tuple_to_album, tuples_to_albums
|
||||
from .utils import SQLiteManager, tuples_to_albums
|
||||
|
||||
|
||||
class SQLiteAlbumMethods:
|
||||
@@ -10,30 +10,15 @@ class SQLiteAlbumMethods:
|
||||
Inserts one album into the database
|
||||
"""
|
||||
|
||||
sql = """INSERT INTO albums(
|
||||
sql = """INSERT OR REPLACE INTO albums(
|
||||
albumhash,
|
||||
colors
|
||||
) VALUES(?,?)
|
||||
"""
|
||||
|
||||
cur.execute(sql, (albumhash, colors))
|
||||
|
||||
return cur.lastrowid
|
||||
|
||||
# @classmethod
|
||||
# def insert_many_albums(cls, albums: list[dict]):
|
||||
# """
|
||||
# Takes a generator of albums, and inserts them into the database
|
||||
|
||||
# Parameters
|
||||
# ----------
|
||||
# albums : Generator
|
||||
# Generator
|
||||
# """
|
||||
# with SQLiteManager() as cur:
|
||||
# for album in albums:
|
||||
# cls.insert_one_album(cur, album["albumhash"], album["colors"])
|
||||
|
||||
@classmethod
|
||||
def get_all_albums(cls):
|
||||
with SQLiteManager() as cur:
|
||||
@@ -45,58 +30,6 @@ class SQLiteAlbumMethods:
|
||||
|
||||
return []
|
||||
|
||||
# @staticmethod
|
||||
# def get_album_by_id(album_id: int):
|
||||
# conn = get_sqlite_conn()
|
||||
# cur = conn.cursor()
|
||||
|
||||
# cur.execute("SELECT * FROM albums WHERE id=?", (album_id,))
|
||||
# album = cur.fetchone()
|
||||
|
||||
# conn.close()
|
||||
|
||||
# if album is None:
|
||||
# return None
|
||||
|
||||
# return tuple_to_album(album)
|
||||
|
||||
@staticmethod
|
||||
def get_album_by_hash(album_hash: str):
|
||||
with SQLiteManager() as cur:
|
||||
cur.execute("SELECT * FROM albums WHERE albumhash=?", (album_hash,))
|
||||
album = cur.fetchone()
|
||||
|
||||
if album is not None:
|
||||
return tuple_to_album(album)
|
||||
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def get_albums_by_hashes(cls, album_hashes: list):
|
||||
"""
|
||||
Gets all the albums with the specified hashes. Returns a generator of albums or an empty list.
|
||||
"""
|
||||
with SQLiteManager() as cur:
|
||||
hashes = ",".join("?" * len(album_hashes))
|
||||
cur.execute(
|
||||
f"SELECT * FROM albums WHERE albumhash IN ({hashes})", album_hashes
|
||||
)
|
||||
albums = cur.fetchall()
|
||||
|
||||
if albums is not None:
|
||||
return tuples_to_albums(albums)
|
||||
|
||||
return []
|
||||
|
||||
# @staticmethod
|
||||
# def update_album_colors(album_hash: str, colors: list[str]):
|
||||
# sql = "UPDATE albums SET colors=? WHERE albumhash=?"
|
||||
|
||||
# colors_str = json.dumps(colors)
|
||||
|
||||
# with SQLiteManager() as cur:
|
||||
# cur.execute(sql, (colors_str, album_hash))
|
||||
|
||||
@staticmethod
|
||||
def get_albums_by_albumartist(albumartist: str):
|
||||
with SQLiteManager() as cur:
|
||||
@@ -107,17 +40,3 @@ class SQLiteAlbumMethods:
|
||||
return tuples_to_albums(albums)
|
||||
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def get_all_albums_raw():
|
||||
"""
|
||||
Returns all the albums in the database, as a list of tuples.
|
||||
"""
|
||||
with SQLiteManager() as cur:
|
||||
cur.execute("SELECT * FROM albums")
|
||||
albums = cur.fetchall()
|
||||
|
||||
if albums is not None:
|
||||
return albums
|
||||
|
||||
return []
|
||||
|
||||
@@ -3,27 +3,27 @@ Contains methods for reading and writing to the sqlite artists database.
|
||||
"""
|
||||
|
||||
import json
|
||||
from sqlite3 import Cursor
|
||||
|
||||
from .utils import SQLiteManager
|
||||
|
||||
|
||||
class SQLiteArtistMethods:
|
||||
@classmethod
|
||||
def insert_one_artist(cls, artisthash: str, colors: str | list[str]):
|
||||
@staticmethod
|
||||
def insert_one_artist(cur: Cursor, artisthash: str, colors: str | list[str]):
|
||||
"""
|
||||
Inserts a single artist into the database.
|
||||
"""
|
||||
sql = """INSERT INTO artists(
|
||||
sql = """INSERT OR REPLACE INTO artists(
|
||||
artisthash,
|
||||
colors
|
||||
) VALUES(?,?)
|
||||
"""
|
||||
colors = json.dumps(colors)
|
||||
cur.execute(sql, (artisthash, colors))
|
||||
|
||||
with SQLiteManager() as cur:
|
||||
cur.execute(sql, (artisthash, colors))
|
||||
|
||||
@classmethod
|
||||
def get_all_artists(cls):
|
||||
@staticmethod
|
||||
def get_all_artists():
|
||||
"""
|
||||
Get all artists from the database and return a generator of Artist objects
|
||||
"""
|
||||
|
||||
@@ -45,13 +45,15 @@ CREATE TABLE IF NOT EXISTS tracks (
|
||||
genre text,
|
||||
title text NOT NULL,
|
||||
track integer NOT NULL,
|
||||
trackhash text NOT NULL
|
||||
trackhash text NOT NULL,
|
||||
UNIQUE (filepath)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS albums (
|
||||
id integer PRIMARY KEY,
|
||||
albumhash text NOT NULL,
|
||||
colors text NOT NULL
|
||||
colors text NOT NULL,
|
||||
UNIQUE (albumhash)
|
||||
);
|
||||
|
||||
|
||||
@@ -60,7 +62,8 @@ CREATE TABLE IF NOT EXISTS artists (
|
||||
id integer PRIMARY KEY,
|
||||
artisthash text NOT NULL,
|
||||
colors text,
|
||||
bio text
|
||||
bio text,
|
||||
UNIQUE (artisthash)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS folders (
|
||||
|
||||
@@ -52,6 +52,7 @@ class SettingsSQLMethods:
|
||||
for _dir in dirs:
|
||||
cur.execute(sql, (_dir,))
|
||||
|
||||
# Not currently used anywhere, to be used later
|
||||
@staticmethod
|
||||
def add_excluded_dirs(dirs: list[str]):
|
||||
"""
|
||||
|
||||
@@ -82,26 +82,6 @@ class SQLiteTrackMethods:
|
||||
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_tracks_by_trackhashes(hashes: list[str]):
|
||||
"""
|
||||
Gets all tracks in a list of trackhashes.
|
||||
Returns a generator of Track objects or an empty list.
|
||||
"""
|
||||
|
||||
sql = "SELECT * FROM tracks WHERE trackhash IN ({})".format(
|
||||
",".join("?" * len(hashes))
|
||||
)
|
||||
|
||||
with SQLiteManager() as cur:
|
||||
cur.execute(sql, hashes)
|
||||
rows = cur.fetchall()
|
||||
|
||||
if rows is not None:
|
||||
return tuples_to_tracks(rows)
|
||||
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def remove_track_by_filepath(filepath: str):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user