[docs]classBaseClient(ABC):"""Base class all clients will inherit from."""__slots__=("logger","cache",)def__init__(self,debug:bool=False)->None:self.logger=LoggerAdapter(anmoku_logger,prefix=self.__class__.__name__)ifdebugisTrue:self.logger.setLevel(logging.DEBUG)super().__init__()
[docs]@abstractmethoddefget(self,resource:Type[ResourceGenericT],id:Optional[StrOrIntT]=None,**kwargs)->ResourceGenericT:"""Get's the exact resource by id."""...
[docs]@abstractmethoddefsearch(self,resource:Type[SearchResourceGenericT],query:str,sfw:bool=True)->SearchResult[SearchResourceGenericT]:"""Searches for the resource and returns a list of the results."""...
[docs]@abstractmethoddefrandom(self,resource:Type[RandomResourceGenericT])->RandomResourceGenericT:"""Fetches a random object of the specified resource."""...
def_format_url(self,unformatted_url:str,resource:Type[ResourceGenericT],*args:str,**kwargs:str)->str:"""Formats the URL while also taking URL encoding into account."""try:formatted_url=unformatted_url.format(*args,**kwargs)exceptKeyErrorase:raiseResourceRequiresError(resource,e.args[0])returnquote(formatted_url)def_raise_http_error(self,data:Mapping[str,Any],status:int):data=cast(ErrorResponseDict,data)ifstatus==404:raiseNotFoundError(data)elifstatus==429:raiseRatelimitError(data)elifstatus>=500:raiseServerError(data)raiseHTTPError(data)