-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add support for HTTP method and response type enums - Introduced `HttpMethod` and `ResponseType` enums to standardize HTTP method usage and response handling. - Updated `BaseRequestHandler` and `ResponseObject` to utilize the new enums for improved code clarity and flexibility. - Modified `RealDebridRequestHandler` and `AllDebridRequestHandler` to use `HttpMethod` and `ResponseType` enums. - Enhanced request handling in downloader classes to support the new enums, ensuring consistent API interactions. * refactor: implement request handler classes for API communication - Introduced new request handler classes for various APIs to streamline HTTP request handling. - Replaced direct requests with handler executions across multiple modules, including TraktAPI, OverseerrAPI, and others. - Enhanced error handling by defining custom exceptions for each API. - Updated session creation and rate limiting configurations for improved performance and reliability. - Improved code readability and maintainability by encapsulating request logic within dedicated classes. * fix: handle missing 'streams' attribute in Torrentio response - Added a check for the presence of the 'streams' attribute in the Torrentio scraper response to prevent errors when the attribute is missing. - Updated the MdblistRequestHandler to include the API key in the request parameters by default, simplifying API calls. - Improved error handling in the ListrrAPI to break on specific HTTP errors. - Enhanced logging for better debugging and error tracking across various modules. * fix: jackett exception handling ordering * feat: add support for overriding response type in request handlers - Introduced an optional `overriden_response_type` parameter in the `_request` method of `BaseRequestHandler` and `execute` method of `PlexRequestHandler`. - Updated `get_items_from_rss` in `PlexAPI` to use `ResponseType.DICT` for RSS feed requests. - Enhanced flexibility in handling different response formats dynamically. * fix: remove retry_if_failed parameter from request handler calls in Orionoid scraper * fix: correct parameter name in Plex RSS feed request handler call
- Loading branch information
1 parent
6d01407
commit d41c2ff
Showing
21 changed files
with
320 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,42 @@ | ||
from program.utils.request import get_rate_limit_params, create_service_session, get, ping | ||
from program.utils.request import get_rate_limit_params, create_service_session, BaseRequestHandler, Session, ResponseType, ResponseObject, HttpMethod | ||
|
||
|
||
class MdblistAPIError(Exception): | ||
"""Base exception for MdblistAPI related errors""" | ||
|
||
class MdblistRequestHandler(BaseRequestHandler): | ||
def __init__(self, session: Session, base_url: str, api_key: str, request_logging: bool = False): | ||
self.api_key = api_key | ||
super().__init__(session, base_url=base_url, response_type=ResponseType.SIMPLE_NAMESPACE, custom_exception=MdblistAPIError, request_logging=request_logging) | ||
|
||
def execute(self, method: HttpMethod, endpoint: str, ignore_base_url: bool = False, **kwargs) -> ResponseObject: | ||
return super()._request(method, endpoint, ignore_base_url=ignore_base_url, params={"apikey": self.api_key}, **kwargs) | ||
|
||
|
||
class MdblistAPI: | ||
"""Handles Mdblist API communication""" | ||
BASE_URL = "https://mdblist.com" | ||
|
||
def __init__(self, api_key: str): | ||
self.api_key = api_key | ||
|
||
rate_limit_params = get_rate_limit_params(per_minute=60) | ||
|
||
self.session = create_service_session( | ||
rate_limit_params=rate_limit_params, | ||
use_cache=False | ||
) | ||
session = create_service_session(rate_limit_params=rate_limit_params) | ||
self.request_handler = MdblistRequestHandler(session, base_url=self.BASE_URL, api_key=api_key) | ||
|
||
def validate(self): | ||
return ping(session=self.session, url=f"{self.BASE_URL}/api/user?apikey={self.api_key}") | ||
return self.request_handler.execute(HttpMethod.GET, f"api/user") | ||
|
||
def my_limits(self): | ||
"""Wrapper for mdblist api method 'My limits'""" | ||
response = get(session=self.session, url=f"{self.BASE_URL}/api/user?apikey={self.api_key}") | ||
response = self.request_handler.execute(HttpMethod.GET,f"api/user") | ||
return response.data | ||
|
||
def list_items_by_id(self, list_id: int): | ||
"""Wrapper for mdblist api method 'List items'""" | ||
response = get(session=self.session, | ||
url=f"{self.BASE_URL}/api/lists/{str(list_id)}/items?apikey={self.api_key}" | ||
) | ||
response = self.request_handler.execute(HttpMethod.GET,f"api/lists/{str(list_id)}/items") | ||
return response.data | ||
|
||
def list_items_by_url(self, url: str): | ||
url = url if url.endswith("/") else f"{url}/" | ||
url = url if url.endswith("json/") else f"{url}json/" | ||
response = get(session=self.session, url=url, params={"apikey": self.api_key}) | ||
response = self.request_handler.execute(HttpMethod.GET, url, ignore_base_url=True) | ||
return response.data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.