|
|
|
@ -217,21 +217,21 @@ class DBAdapter:
|
|
|
|
|
|
|
|
|
|
return new_rows
|
|
|
|
|
|
|
|
|
|
def save_artist(self, ID: int, description: str):
|
|
|
|
|
def save_artist(self, ID: int, name: str):
|
|
|
|
|
"""
|
|
|
|
|
Save (or update if ID is already taken) an artist to the DB
|
|
|
|
|
:param ID:
|
|
|
|
|
:param description:
|
|
|
|
|
:param name:
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
print("Saving artist {0}:{1}".format(ID, description))
|
|
|
|
|
d = {"id": ID, "description": description}
|
|
|
|
|
print("Saving artist {0}:{1}".format(ID, name))
|
|
|
|
|
d = {"id": ID, "name": name}
|
|
|
|
|
if ID is None: # no ID given, auto generate it
|
|
|
|
|
self.db_cursor.execute("INSERT INTO artist (description) VALUES (%(description)s)", d)
|
|
|
|
|
self.db_cursor.execute("INSERT INTO artist (name) VALUES (%(name)s)", d)
|
|
|
|
|
elif len(self.get_artist(ID)) != 0: # artist exists already:
|
|
|
|
|
self.db_cursor.execute("UPDATE artist SET description = %(description)s WHERE id = %(id)s", d)
|
|
|
|
|
self.db_cursor.execute("UPDATE artist SET name = %(name)s WHERE id = %(id)s", d)
|
|
|
|
|
else: # artist needs to be created
|
|
|
|
|
self.db_cursor.execute("INSERT INTO artist (id, description) VALUES (%(id)s, %(description)s)", d)
|
|
|
|
|
self.db_cursor.execute("INSERT INTO artist (id, name) VALUES (%(id)s, %(name)s)", d)
|
|
|
|
|
self.db.commit()
|
|
|
|
|
|
|
|
|
|
def remove_artist(self, ID: int):
|
|
|
|
@ -313,7 +313,7 @@ class DBAdapter:
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
d = {"id": ID}
|
|
|
|
|
self.db_cursor.execute("SELECT id, description FROM artist WHERE id = %(id)s", d)
|
|
|
|
|
self.db_cursor.execute("SELECT id, name FROM artist WHERE id = %(id)s", d)
|
|
|
|
|
|
|
|
|
|
return self.db_cursor.fetchall()
|
|
|
|
|
|
|
|
|
@ -333,7 +333,7 @@ class DBAdapter:
|
|
|
|
|
Lists all available artists (not presences) and returns the result
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
self.db_cursor.execute("SELECT id, description FROM artist")
|
|
|
|
|
self.db_cursor.execute("SELECT id, name FROM artist")
|
|
|
|
|
|
|
|
|
|
def get_art_by_hash(self, file_hash: str) -> dict:
|
|
|
|
|
"""
|
|
|
|
@ -529,23 +529,23 @@ class DBAdapter:
|
|
|
|
|
|
|
|
|
|
return new_rows
|
|
|
|
|
|
|
|
|
|
def search_fuzzy_artists(self, ID: int, description: str, all_if_empty: bool = False):
|
|
|
|
|
def search_fuzzy_artists(self, ID: int, name: str, all_if_empty: bool = False):
|
|
|
|
|
"""
|
|
|
|
|
Search a list of fitting artists fuzzy.
|
|
|
|
|
|
|
|
|
|
If ID is None it will search using the description
|
|
|
|
|
:param ID:
|
|
|
|
|
:param description:
|
|
|
|
|
:param name:
|
|
|
|
|
:param all_if_empty:
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
if ID is not None:
|
|
|
|
|
self.db_cursor.execute("SELECT id, description FROM artist WHERE id = %(id)s", {"id": ID})
|
|
|
|
|
elif all_if_empty and ID is None and len(description) == 0:
|
|
|
|
|
self.db_cursor.execute("SELECT id, description FROM artist")
|
|
|
|
|
self.db_cursor.execute("SELECT id, name FROM artist WHERE id = %(id)s", {"id": ID})
|
|
|
|
|
elif all_if_empty and ID is None and len(name) == 0:
|
|
|
|
|
self.db_cursor.execute("SELECT id, name FROM artist")
|
|
|
|
|
else:
|
|
|
|
|
self.db_cursor.execute("SELECT id, description FROM artist WHERE LOWER(description) LIKE LOWER('%{0}%')"
|
|
|
|
|
.format(description))
|
|
|
|
|
self.db_cursor.execute("SELECT id, name FROM artist WHERE LOWER(name) LIKE LOWER('%{0}%')"
|
|
|
|
|
.format(name))
|
|
|
|
|
|
|
|
|
|
return self.db_cursor.fetchall()
|
|
|
|
|
|
|
|
|
|