@@ -5,15 +5,18 @@ import sys
|
||||
sys.path.insert(1,'..')
|
||||
import traceback
|
||||
import logging
|
||||
import time
|
||||
from typing import Optional
|
||||
from aiohttp import ClientTimeout, ClientSession
|
||||
from bs4 import BeautifulSoup, ResultSet
|
||||
import html as htm
|
||||
from . import private
|
||||
from . import common
|
||||
from . import cache
|
||||
from lyric_search_new import utils
|
||||
from lyric_search_new.constructors import LyricsResult
|
||||
|
||||
|
||||
logger = logging.getLogger()
|
||||
log_level = logging.getLevelName(logger.level)
|
||||
|
||||
@@ -32,6 +35,7 @@ class Genius:
|
||||
self.timeout = ClientTimeout(connect=2, sock_read=4)
|
||||
self.datautils = utils.DataUtils()
|
||||
self.matcher = utils.TrackMatcher()
|
||||
self.cache = cache.Cache()
|
||||
|
||||
async def search(self, artist: str, song: str) -> Optional[LyricsResult]:
|
||||
"""
|
||||
@@ -41,6 +45,7 @@ class Genius:
|
||||
try:
|
||||
artist: str = artist.strip().lower()
|
||||
song: str = song.strip().lower()
|
||||
time_start: float = time.time()
|
||||
logging.info("Searching %s - %s on %s",
|
||||
artist, song, self.label)
|
||||
search_term: str = f'{artist}%20{song}'
|
||||
@@ -104,15 +109,20 @@ class Genius:
|
||||
artist: str = track.split(" - ", maxsplit=1)[0]
|
||||
song: str = track.split(" - ", maxsplit=1)[1]
|
||||
logging.info("Result found on %s", self.label)
|
||||
return LyricsResult(artist=artist,
|
||||
time_end: float = time.time()
|
||||
time_diff: float = time_end - time_start
|
||||
matched = LyricsResult(artist=artist,
|
||||
song=song,
|
||||
src=self.label,
|
||||
lyrics=returned_lyrics,
|
||||
confidence=confidence)
|
||||
confidence=confidence,
|
||||
time=time_diff)
|
||||
await self.cache.store(matched)
|
||||
return matched
|
||||
|
||||
except:
|
||||
if log_level == "DEBUG":
|
||||
traceback.print_exc()
|
||||
# if log_level == "DEBUG":
|
||||
traceback.print_exc()
|
||||
return
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user