sok.core.media_manager
Universal media manager for coordinating API access.
Provides a unified interface to search and retrieve media metadata from multiple API sources (TMDB, Spotify, IGDB, etc.) based on media type.
UniversalMediaManager
class UniversalMediaManager(load_defaults: bool = True)Universal manager for all media types and APIs.
Provides a unified interface to interact with multiple media APIs (TMDB, TVDB, Spotify, etc.) for searching and retrieving details about movies, TV shows, music, books, and games.
Initialize the media manager.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
load_defaults | bool | True | If True, automatically loads and registers all available APIs based on configuration. |
Attributes
| Name | Type | Description |
|---|---|---|
apis | Dict[str, MediaAPI] | Dictionary mapping API names to their instances. |
current_apis | Dict[MediaType, str] | Dictionary mapping media types to their currently selected API. |
get_available_apis_for_media_type
def get_available_apis_for_media_type(media_type: MediaType) -> List[str]:Return available APIs for a media type.
Parameters
| Name | Type | Description |
|---|---|---|
media_type | MediaType | The media type to query. |
Returns
List[str]List of API names that support the given media type.
get_current_api
def get_current_api(media_type: MediaType) -> MediaAPI:Return the current API for a media type.
Parameters
| Name | Type | Description |
|---|---|---|
media_type | MediaType | The media type to get the API for. |
Returns
MediaAPIThe currently selected API instance for the media type.
Raises
UnsupportedMediaTypeErrorIf no API is available for the media type.
get_detailsasync
async def get_details( item_id: str, content_type: ContentType, **kwargs: Any,) -> Dict[str, Any]:Get detailed information about a media item.
Parameters
| Name | Type | Description |
|---|---|---|
item_id | str | Unique identifier of the item. |
content_type | ContentType | Type of content. |
**kwargs | Any | Additional parameters (e.g., language, append_to_response). |
Returns
Dict[str, Any]Dict containing detailed information about the item.
Raises
APITimeoutErrorIf the request times out.APIConnectionErrorIf connection to API fails.APIResponseErrorIf API returns invalid response.APIErrorFor any other API-related errors.
register_api
def register_api(name: str, api_instance: MediaAPI) -> None:Register a new API instance.
Parameters
| Name | Type | Description |
|---|---|---|
name | str | Unique identifier for the API (e.g., 'tmdb', 'spotify'). |
api_instance | MediaAPI | The API client instance implementing MediaAPI. |
searchasync
async def search( query: str, content_type: ContentType, **kwargs: Any,) -> Dict[str, Any]:Search for media using the appropriate API.
Parameters
| Name | Type | Description |
|---|---|---|
query | str | Search query string. |
content_type | ContentType | Type of content to search for. |
**kwargs | Any | Additional API-specific parameters (e.g., language, year). |
Returns
Dict[str, Any]Dict containing 'results' key with list of matching items.
Raises
APITimeoutErrorIf the request times out.APIConnectionErrorIf connection to API fails.APIResponseErrorIf API returns invalid response.APIErrorFor any other API-related errors.
set_current_api_for_media_type
def set_current_api_for_media_type( media_type: MediaType, api_name: str,) -> None:Set the current API for a media type.
Parameters
| Name | Type | Description |
|---|---|---|
media_type | MediaType | The media type (VIDEO, MUSIC, BOOK, GAME). |
api_name | str | Name of the registered API to use. |
Raises
APINotFoundErrorIf the API is not registered.UnsupportedMediaTypeErrorIf the API doesn't support the media type.
Functions
get_media_manager
def get_media_manager() -> UniversalMediaManager:Get the singleton instance of UniversalMediaManager.
Returns
UniversalMediaManagerThe shared manager instance.
reset_media_manager
def reset_media_manager() -> None:Reset the singleton (useful for testing).
SourceAttributes
| Name | Value |
|---|---|
logger | logging.getLogger(__name__) |