add retries for genius/lrclib searches (tenacity) + reduce timeouts appropriately
This commit is contained in:
		| @@ -8,6 +8,9 @@ import re | |||||||
| from typing import Optional | from typing import Optional | ||||||
| from aiohttp import ClientTimeout, ClientSession | from aiohttp import ClientTimeout, ClientSession | ||||||
| from bs4 import BeautifulSoup, ResultSet  # type: ignore | from bs4 import BeautifulSoup, ResultSet  # type: ignore | ||||||
|  | from tenacity import ( | ||||||
|  |     retry, stop_after_attempt, wait_fixed | ||||||
|  | ) | ||||||
| import html as htm | import html as htm | ||||||
| from . import private, common, cache, redis_cache | from . import private, common, cache, redis_cache | ||||||
| from lyric_search import utils | from lyric_search import utils | ||||||
| @@ -27,12 +30,13 @@ class Genius: | |||||||
|         self.genius_url: str = private.GENIUS_URL |         self.genius_url: str = private.GENIUS_URL | ||||||
|         self.genius_search_url: str = f"{self.genius_url}api/search/song?q=" |         self.genius_search_url: str = f"{self.genius_url}api/search/song?q=" | ||||||
|         self.headers: dict = common.SCRAPE_HEADERS |         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.datautils = utils.DataUtils() | ||||||
|         self.matcher = utils.TrackMatcher() |         self.matcher = utils.TrackMatcher() | ||||||
|         self.cache = cache.Cache() |         self.cache = cache.Cache() | ||||||
|         self.redis_cache = redis_cache.RedisCache() |         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]: |     async def search(self, artist: str, song: str, **kwargs) -> Optional[LyricsResult]: | ||||||
|         """ |         """ | ||||||
|         Genius Search |         Genius Search | ||||||
|   | |||||||
| @@ -6,6 +6,9 @@ import traceback | |||||||
| import logging | import logging | ||||||
| from typing import Optional, Union | from typing import Optional, Union | ||||||
| from aiohttp import ClientTimeout, ClientSession | from aiohttp import ClientTimeout, ClientSession | ||||||
|  | from tenacity import ( | ||||||
|  |     retry, stop_after_attempt, wait_fixed | ||||||
|  | ) | ||||||
| from lyric_search import utils | from lyric_search import utils | ||||||
| from lyric_search.constructors import LyricsResult | from lyric_search.constructors import LyricsResult | ||||||
| from . import common, cache, redis_cache | from . import common, cache, redis_cache | ||||||
| @@ -22,12 +25,13 @@ class LRCLib: | |||||||
|         self.label: str = "LRCLib" |         self.label: str = "LRCLib" | ||||||
|         self.lrclib_url: str = "https://lrclib.net/api/search" |         self.lrclib_url: str = "https://lrclib.net/api/search" | ||||||
|         self.headers: dict = common.SCRAPE_HEADERS |         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.datautils = utils.DataUtils() | ||||||
|         self.matcher = utils.TrackMatcher() |         self.matcher = utils.TrackMatcher() | ||||||
|         self.cache = cache.Cache() |         self.cache = cache.Cache() | ||||||
|         self.redis_cache = redis_cache.RedisCache() |         self.redis_cache = redis_cache.RedisCache() | ||||||
|  |  | ||||||
|  |     @retry(stop=stop_after_attempt(2), wait=wait_fixed(0.5)) | ||||||
|     async def search( |     async def search( | ||||||
|         self, artist: str, song: str, plain: Optional[bool] = True |         self, artist: str, song: str, plain: Optional[bool] = True | ||||||
|     ) -> Optional[LyricsResult]: |     ) -> Optional[LyricsResult]: | ||||||
|   | |||||||
| @@ -50,12 +50,12 @@ class RadioUtil: | |||||||
|             "/usr/local/share", "sqlite_dbs", "track_album_art.db" |             "/usr/local/share", "sqlite_dbs", "track_album_art.db" | ||||||
|         ) |         ) | ||||||
|         self.playback_genres: list[str] = [ |         self.playback_genres: list[str] = [ | ||||||
|             # "post-hardcore", |             "post-hardcore", | ||||||
|             # "post hardcore", |             "post hardcore", | ||||||
|             # "metalcore", |             "metalcore", | ||||||
|             # "deathcore", |             "deathcore", | ||||||
|             # "edm", |             "edm", | ||||||
|             # "electronic", |             "electronic", | ||||||
|         ] |         ] | ||||||
|         self.active_playlist: list[dict] = [] |         self.active_playlist: list[dict] = [] | ||||||
|         self.playlist_loaded: bool = False |         self.playlist_loaded: bool = False | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user