sok.config.session_manager
Session Manager - Centralized management of sessions and API keys.
This module provides utilities for retrieving sessions and API keys from configuration.
Functions
get_api_key
def get_api_key(config: ConfigManager, service_id: str) -> str:Retrieve the API key for a service from config or environment.
Parameters
| Name | Type | Description |
|---|---|---|
config | ConfigManager | ConfigManager instance. |
service_id | str | Service identifier. |
Returns
strAPI key string or empty string if not found.
get_igdb_token
def get_igdb_token(config: ConfigManager, renew: bool = False) -> Optional[str]:The Twitch token that IGDB asks for, made from the client ID and secret.
The token is asked from Twitch (client credentials) the first time, kept
in memory until an hour before it expires (about 60 days), and asked
again when renew is set (IGDB refused it). Nothing is saved: the
server and the desktop app each ask for their own.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
config | ConfigManager | ConfigManager instance. | |
renew | bool | False | Ask for a new token even if the one kept is still valid. |
Returns
Optional[str]IGDB access token string, or None without the client ID and secretOptional[str]or when Twitch does not answer.
get_session_data
def get_session_data( config: ConfigManager, service_id: str,) -> Optional[Dict[str, Any]]:Extract session data for a service from the config.
Works for all services (tmdb, lastfm, tvdb, etc.).
Parameters
| Name | Type | Description |
|---|---|---|
config | ConfigManager | ConfigManager instance. |
service_id | str | Service identifier (tmdb, tvdb, lastfm, etc.). |
Returns
Optional[Dict[str, Any]]Dictionary containing session data or None if not found.
get_spotify_token
def get_spotify_token(config: ConfigManager) -> Optional[str]:Extract the Spotify token from the config.
Parameters
| Name | Type | Description |
|---|---|---|
config | ConfigManager | ConfigManager instance. |
Returns
Optional[str]Spotify access token string or None if not found.
get_tmdb_session_id
def get_tmdb_session_id(config: ConfigManager) -> Optional[str]:Extract the TMDB session_id from the config.
Parameters
| Name | Type | Description |
|---|---|---|
config | ConfigManager | ConfigManager instance. |
Returns
Optional[str]TMDB session ID string or None if not found.
get_tvdb_token
def get_tvdb_token(config: ConfigManager) -> Optional[str]:Extract the TVDB token from the config.
Parameters
| Name | Type | Description |
|---|---|---|
config | ConfigManager | ConfigManager instance. |
Returns
Optional[str]TVDB token string or None if not found.
Attributes
| Name | Value |
|---|---|
TOKEN_MARGIN_SECONDS | 3600 |
TWITCH_TOKEN_URL | 'https://id.twitch.tv/oauth2/token' |
logger | logging.getLogger(__name__) |