Compare commits

...

2 Commits

View File

@ -170,6 +170,30 @@ class RadioUtil:
traceback.print_exc()
return False
async def add_genre(self, artist: str, genre: str) -> bool:
"""
Add artist/genre pairing to DB
Args:
artist (str)
genre (str)
Returns:
bool
"""
try:
async with sqlite3.connect(self.artist_genre_db_path, timeout=2) as _db:
query: str = "INSERT OR IGNORE INTO artist_genre (artist, genre) VALUES(?, ?)"
params: tuple[str, str] = (artist, genre)
res = await _db.execute_insert(query, params)
if res:
return True
return False
except Exception as e:
logging.info("Failed to store artist/genre pair: %s/%s (%s)",
artist, genre, str(e))
traceback.print_exc()
return False
async def get_genre(self, artist: str) -> str:
"""
Retrieve Genre for given Artist
@ -180,8 +204,8 @@ class RadioUtil:
"""
try:
artist = artist.strip()
query = "SELECT genre FROM artist_genre WHERE artist LIKE ?"
params = (f"%%{artist}%%",)
query: str = "SELECT genre FROM artist_genre WHERE artist LIKE ?"
params: tuple[str] = (f"%%{artist}%%",)
async with sqlite3.connect(self.artist_genre_db_path, timeout=2) as _db:
_db.row_factory = sqlite3.Row
async with await _db.execute(query, params) as _cursor:
@ -305,7 +329,7 @@ class RadioUtil:
async with sqlite3.connect(self.album_art_db_path, timeout=2) as db_conn:
db_conn.row_factory = sqlite3.Row
query: str = "SELECT album_art FROM album_art WHERE track_id = ?"
query_params: tuple = (track_id,)
query_params: tuple[int] = (track_id,)
async with await db_conn.execute(query, query_params) as db_cursor:
result: Optional[Union[sqlite3.Row, bool]] = (