diff --git a/utils/radio_util.py b/utils/radio_util.py index c972261..7b3f74b 100644 --- a/utils/radio_util.py +++ b/utils/radio_util.py @@ -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