diff --git a/lyric_search/sources/genius.py b/lyric_search/sources/genius.py index 20a846f..43c26fd 100644 --- a/lyric_search/sources/genius.py +++ b/lyric_search/sources/genius.py @@ -8,6 +8,9 @@ import re from typing import Optional from aiohttp import ClientTimeout, ClientSession from bs4 import BeautifulSoup, ResultSet # type: ignore +from tenacity import ( + retry, stop_after_attempt, wait_fixed +) import html as htm from . import private, common, cache, redis_cache from lyric_search import utils @@ -27,12 +30,13 @@ class Genius: self.genius_url: str = private.GENIUS_URL self.genius_search_url: str = f"{self.genius_url}api/search/song?q=" self.headers: dict = common.SCRAPE_HEADERS - self.timeout = ClientTimeout(connect=5, sock_read=7) + self.timeout = ClientTimeout(connect=2, sock_read=5) self.datautils = utils.DataUtils() self.matcher = utils.TrackMatcher() self.cache = cache.Cache() self.redis_cache = redis_cache.RedisCache() + @retry(stop=stop_after_attempt(2), wait=wait_fixed(0.5)) async def search(self, artist: str, song: str, **kwargs) -> Optional[LyricsResult]: """ Genius Search diff --git a/lyric_search/sources/lrclib.py b/lyric_search/sources/lrclib.py index 04a3068..b0b4b39 100644 --- a/lyric_search/sources/lrclib.py +++ b/lyric_search/sources/lrclib.py @@ -6,6 +6,9 @@ import traceback import logging from typing import Optional, Union from aiohttp import ClientTimeout, ClientSession +from tenacity import ( + retry, stop_after_attempt, wait_fixed +) from lyric_search import utils from lyric_search.constructors import LyricsResult from . import common, cache, redis_cache @@ -22,12 +25,13 @@ class LRCLib: self.label: str = "LRCLib" self.lrclib_url: str = "https://lrclib.net/api/search" self.headers: dict = common.SCRAPE_HEADERS - self.timeout = ClientTimeout(connect=2, sock_read=4) + self.timeout = ClientTimeout(connect=2, sock_read=3) self.datautils = utils.DataUtils() self.matcher = utils.TrackMatcher() self.cache = cache.Cache() self.redis_cache = redis_cache.RedisCache() + @retry(stop=stop_after_attempt(2), wait=wait_fixed(0.5)) async def search( self, artist: str, song: str, plain: Optional[bool] = True ) -> Optional[LyricsResult]: diff --git a/utils/radio_util.py b/utils/radio_util.py index 3faa55f..fbd2e34 100644 --- a/utils/radio_util.py +++ b/utils/radio_util.py @@ -50,12 +50,12 @@ class RadioUtil: "/usr/local/share", "sqlite_dbs", "track_album_art.db" ) self.playback_genres: list[str] = [ - # "post-hardcore", - # "post hardcore", - # "metalcore", - # "deathcore", - # "edm", - # "electronic", + "post-hardcore", + "post hardcore", + "metalcore", + "deathcore", + "edm", + "electronic", ] self.active_playlist: list[dict] = [] self.playlist_loaded: bool = False