Skip to content

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

NameTypeDefaultDescription
load_defaultsboolTrueIf True, automatically loads and registers all available APIs based on configuration.
Source

Attributes

NameTypeDescription
apisDict[str, MediaAPI]

Dictionary mapping API names to their instances.

current_apisDict[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

NameTypeDescription
media_typeMediaTypeThe media type to query.

Returns

  • List[str]List of API names that support the given media type.
Source

get_current_api

def get_current_api(media_type: MediaType) -> MediaAPI:

Return the current API for a media type.

Parameters

NameTypeDescription
media_typeMediaTypeThe media type to get the API for.

Returns

  • MediaAPIThe currently selected API instance for the media type.

Raises

Source

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

NameTypeDescription
item_idstrUnique identifier of the item.
content_typeContentTypeType of content.
**kwargsAnyAdditional parameters (e.g., language, append_to_response).

Returns

  • Dict[str, Any]Dict containing detailed information about the item.

Raises

Source

register_api

def register_api(name: str, api_instance: MediaAPI) -> None:

Register a new API instance.

Parameters

NameTypeDescription
namestrUnique identifier for the API (e.g., 'tmdb', 'spotify').
api_instanceMediaAPIThe API client instance implementing MediaAPI.
Source
async def search(
query: str,
content_type: ContentType,
**kwargs: Any,
) -> Dict[str, Any]:

Search for media using the appropriate API.

Parameters

NameTypeDescription
querystrSearch query string.
content_typeContentTypeType of content to search for.
**kwargsAnyAdditional API-specific parameters (e.g., language, year).

Returns

  • Dict[str, Any]Dict containing 'results' key with list of matching items.

Raises

Source

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

NameTypeDescription
media_typeMediaTypeThe media type (VIDEO, MUSIC, BOOK, GAME).
api_namestrName of the registered API to use.

Raises

Source

Functions

get_media_manager

def get_media_manager() -> UniversalMediaManager:

Get the singleton instance of UniversalMediaManager.

Returns

Source

reset_media_manager

def reset_media_manager() -> None:

Reset the singleton (useful for testing).

Source

Attributes

NameValue
loggerlogging.getLogger(__name__)
Built with Kiln