cleanup
This commit is contained in:
parent
d58f2f9413
commit
00be1b8eb1
@ -24,7 +24,8 @@ class Cache:
|
|||||||
"lib", "singerdbs",
|
"lib", "singerdbs",
|
||||||
"cached_lyrics.db")
|
"cached_lyrics.db")
|
||||||
|
|
||||||
self.cache_pre_query: str = "pragma journal_mode = WAL; pragma synchronous = normal; pragma temp_store = memory; pragma mmap_size = 30000000000;"
|
self.cache_pre_query: str = "pragma journal_mode = WAL; pragma synchronous = normal;\
|
||||||
|
pragma temp_store = memory; pragma mmap_size = 30000000000;"
|
||||||
self.sqlite_exts: list[str] = ['/usr/local/lib/python3.11/dist-packages/spellfix1.cpython-311-x86_64-linux-gnu.so']
|
self.sqlite_exts: list[str] = ['/usr/local/lib/python3.11/dist-packages/spellfix1.cpython-311-x86_64-linux-gnu.so']
|
||||||
self.label: str = "Cache"
|
self.label: str = "Cache"
|
||||||
|
|
||||||
@ -52,12 +53,13 @@ class Cache:
|
|||||||
check_query = "SELECT id FROM lyrics WHERE artistsong LIKE ? LIMIT 1"
|
check_query = "SELECT id FROM lyrics WHERE artistsong LIKE ? LIMIT 1"
|
||||||
params = (f"%{artistsong}%",)
|
params = (f"%{artistsong}%",)
|
||||||
async with sqlite3.connect(self.cache_db, timeout=2) as db_conn:
|
async with sqlite3.connect(self.cache_db, timeout=2) as db_conn:
|
||||||
async with db_conn.execute(check_query, params) as db_cursor:
|
async with await db_conn.executescript(self.cache_pre_query) as _db_cursor:
|
||||||
result = await db_cursor.fetchone()
|
async with await db_conn.execute(check_query, params) as db_cursor:
|
||||||
if result:
|
result = await db_cursor.fetchone()
|
||||||
logging.debug("%s is already stored.",
|
if result:
|
||||||
artistsong.replace("\n", " - "))
|
logging.debug("%s is already stored.",
|
||||||
return True
|
artistsong.replace("\n", " - "))
|
||||||
|
return True
|
||||||
logging.debug("%s cleared to be stored.",
|
logging.debug("%s cleared to be stored.",
|
||||||
artistsong)
|
artistsong)
|
||||||
return False
|
return False
|
||||||
@ -91,8 +93,9 @@ class Cache:
|
|||||||
lyr_result.song, artistsong, lyr_result.confidence, lyrics)
|
lyr_result.song, artistsong, lyr_result.confidence, lyrics)
|
||||||
|
|
||||||
async with sqlite3.connect(self.cache_db, timeout=2) as db_conn:
|
async with sqlite3.connect(self.cache_db, timeout=2) as db_conn:
|
||||||
async with db_conn.execute(insert_query, params) as _cursor:
|
async with await db_conn.executescript(self.cache_pre_query) as _db_cursor:
|
||||||
await db_conn.commit()
|
async with await db_conn.execute(insert_query, params) as _cursor:
|
||||||
|
await db_conn.commit()
|
||||||
logging.info("Stored %s!", artistsong.replace("\n", " - "))
|
logging.info("Stored %s!", artistsong.replace("\n", " - "))
|
||||||
except:
|
except:
|
||||||
logging.critical("Cache storage error!")
|
logging.critical("Cache storage error!")
|
||||||
@ -160,7 +163,3 @@ class Cache:
|
|||||||
if log_level == "DEBUG":
|
if log_level == "DEBUG":
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -124,5 +124,3 @@ class Genius:
|
|||||||
# if log_level == "DEBUG":
|
# if log_level == "DEBUG":
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@ -113,5 +113,3 @@ class LRCLib:
|
|||||||
if log_level == "DEBUG":
|
if log_level == "DEBUG":
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user