misc
This commit is contained in:
@ -89,8 +89,10 @@ class Cache:
|
||||
logging.debug(
|
||||
"Checking whether %s is already stored", artistsong.replace("\n", " - ")
|
||||
)
|
||||
check_query: str = 'SELECT id, artist, song FROM lyrics WHERE editdist3((lower(artist) || " " || lower(song)), (? || " " || ?))\
|
||||
check_query: str = (
|
||||
'SELECT id, artist, song FROM lyrics WHERE editdist3((lower(artist) || " " || lower(song)), (? || " " || ?))\
|
||||
<= 410 ORDER BY editdist3((lower(artist) || " " || lower(song)), ?) ASC LIMIT 1'
|
||||
)
|
||||
artistsong_split = artistsong.split("\n", maxsplit=1)
|
||||
artist = artistsong_split[0].lower()
|
||||
song = artistsong_split[1].lower()
|
||||
@ -211,10 +213,8 @@ class Cache:
|
||||
lyrics = regex.sub(r"(<br>|\n|\r\n)", " / ", lyr_result.lyrics.strip())
|
||||
lyrics = regex.sub(r"\s{2,}", " ", lyrics)
|
||||
|
||||
insert_query = (
|
||||
"INSERT INTO lyrics (src, date_retrieved, artist, song, artistsong, confidence, lyrics)\
|
||||
insert_query = "INSERT INTO lyrics (src, date_retrieved, artist, song, artistsong, confidence, lyrics)\
|
||||
VALUES(?, ?, ?, ?, ?, ?, ?)"
|
||||
)
|
||||
params = (
|
||||
lyr_result.src,
|
||||
time.time(),
|
||||
@ -233,8 +233,8 @@ class Cache:
|
||||
await db_conn.commit()
|
||||
logging.info("Stored %s to SQLite!", artistsong.replace("\n", " - "))
|
||||
return _cursor.lastrowid
|
||||
except:
|
||||
logging.critical("Cache storage error!")
|
||||
except Exception as e:
|
||||
logging.critical("Cache storage error: %s", str(e))
|
||||
traceback.print_exc()
|
||||
|
||||
async def search(self, artist: str, song: str, **kwargs) -> Optional[LyricsResult]:
|
||||
@ -258,8 +258,10 @@ class Cache:
|
||||
|
||||
if artist == "!" and song == "!":
|
||||
random_search = True
|
||||
search_query: str = "SELECT id, artist, song, lyrics, src, confidence\
|
||||
search_query: str = (
|
||||
"SELECT id, artist, song, lyrics, src, confidence\
|
||||
FROM lyrics ORDER BY RANDOM() LIMIT 1"
|
||||
)
|
||||
|
||||
logging.info("Searching %s - %s on %s", artist, song, self.label)
|
||||
|
||||
@ -304,7 +306,8 @@ class Cache:
|
||||
)
|
||||
await self.redis_cache.increment_found_count(self.label)
|
||||
return matched
|
||||
except:
|
||||
except Exception as e:
|
||||
logging.debug(str(e))
|
||||
pass
|
||||
|
||||
"""SQLite: Fallback"""
|
||||
@ -317,9 +320,11 @@ class Cache:
|
||||
self.cache_pre_query
|
||||
) as _db_cursor:
|
||||
if not random_search:
|
||||
search_query: str = 'SELECT id, artist, song, lyrics, src, confidence FROM lyrics\
|
||||
search_query: str = (
|
||||
'SELECT id, artist, song, lyrics, src, confidence FROM lyrics\
|
||||
WHERE editdist3((lower(artist) || " " || lower(song)), (? || " " || ?))\
|
||||
<= 410 ORDER BY editdist3((lower(artist) || " " || lower(song)), ?) ASC LIMIT 10'
|
||||
)
|
||||
search_params: tuple = (
|
||||
artist.strip(),
|
||||
song.strip(),
|
||||
@ -354,5 +359,6 @@ class Cache:
|
||||
matched.time = time_diff
|
||||
await self.redis_cache.increment_found_count(self.label)
|
||||
return matched
|
||||
except:
|
||||
except Exception as e:
|
||||
logging.info("Exception: %s", str(e))
|
||||
traceback.print_exc()
|
||||
|
@ -1,5 +1,5 @@
|
||||
from difflib import SequenceMatcher
|
||||
from typing import List, Optional, Union, Any
|
||||
from typing import List, Optional
|
||||
import logging
|
||||
import regex
|
||||
from regex import Pattern
|
||||
|
Reference in New Issue
Block a user