sok.config.config_manager
Configuration Manager for S.O.K
AppConfigdataclass
class AppConfig( language: str = 'en', theme: str = 'system' if sys.platform == 'darwin' else 'dark', use_system_accent: bool = False, is_prod: bool = HAS_SECURE_CONSTANTS, api_key_tmdb_v4: str = '', api_key_tvdb: str = '', api_key_omdb: str = '', api_key_lastfm: str = '', spotify_client_id: str = '', spotify_client_secret: str = '', google_books_api_key: str = '', igdb_client_id: str = '', igdb_client_secret: str = '', api_key_rawg: str = '', api_key_fanart: str = '', client_id_discord: str = '', default_video_path: str = '', default_music_path: str = '', default_books_path: str = '', default_games_path: str = '', create_folders: bool = True, download_posters: bool = False, use_discord_rpc: bool = False, check_updates: bool = True, video_format: str = '{title} S{season}E{episode} {episode_title}', movie_format: str = '{title} ({year})', music_format: str = '{artist} - {album}/{track} - {title}', book_format: str = '{author} - {title} ({year})', game_format: str = '{title} {tags}', input_patterns: Dict[str, List[str]] = dict(), backup_before_rename: bool = True, skip_duplicates: bool = True, subtitles_follow_video: bool = True, file_mode: str = 'move', log_operations: bool = True, preferred_api_video: str = SERVICE_TMDB, preferred_api_music: str = SERVICE_DEEZER, preferred_api_books: str = SERVICE_GOOGLE_BOOKS, preferred_api_games: str = SERVICE_IGDB,)Application configuration data class.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
language | str | 'en' | UI language code |
theme | str | 'system' if sys.platform == 'darwin' else 'dark' | UI theme (dark, light, or system to follow the OS on macOS) |
use_system_accent | bool | False | Use the system accent color instead of orange (macOS) |
is_prod | bool | HAS_SECURE_CONSTANTS | Whether the app is running in production (compiled) mode |
api_key_tmdb_v4 | str | '' | |
api_key_tvdb | str | '' | |
api_key_omdb | str | '' | |
api_key_lastfm | str | '' | |
spotify_client_id | str | '' | |
spotify_client_secret | str | '' | |
google_books_api_key | str | '' | |
igdb_client_id | str | '' | |
igdb_client_secret | str | '' | |
api_key_rawg | str | '' | |
api_key_fanart | str | '' | |
client_id_discord | str | '' | |
default_video_path | str | '' | |
default_music_path | str | '' | |
default_books_path | str | '' | |
default_games_path | str | '' | |
create_folders | bool | True | |
download_posters | bool | False | |
use_discord_rpc | bool | False | |
check_updates | bool | True | |
video_format | str | '{title} S{season}E{episode} {episode_title}' | |
movie_format | str | '{title} ({year})' | |
music_format | str | '{artist} - {album}/{track} - {title}' | |
book_format | str | '{author} - {title} ({year})' | |
game_format | str | '{title} {tags}' | |
input_patterns | Dict[str, List[str]] | dict() | |
backup_before_rename | bool | True | |
skip_duplicates | bool | True | |
subtitles_follow_video | bool | True | |
file_mode | str | 'move' | |
log_operations | bool | True | |
preferred_api_video | str | SERVICE_TMDB | |
preferred_api_music | str | SERVICE_DEEZER | |
preferred_api_books | str | SERVICE_GOOGLE_BOOKS | |
preferred_api_games | str | SERVICE_IGDB |
Attributes
| Name | Type | Description |
|---|---|---|
api_key_fanart | str | |
api_key_lastfm | str | |
api_key_omdb | str | |
api_key_rawg | str | |
api_key_tmdb_v4 | str | |
api_key_tvdb | str | |
backup_before_rename | bool | |
book_format | str | |
check_updates | bool | |
client_id_discord | str | |
create_folders | bool | |
default_books_path | str | |
default_games_path | str | |
default_music_path | str | |
default_video_path | str | |
download_posters | bool | |
file_mode | str | |
game_format | str | |
google_books_api_key | str | |
igdb_client_id | str | |
igdb_client_secret | str | |
input_patterns | Dict[str, List[str]] | |
is_prod | bool | Whether the app is running in production (compiled) mode |
language | str | UI language code |
log_operations | bool | |
movie_format | str | |
music_format | str | |
preferred_api_books | str | |
preferred_api_games | str | |
preferred_api_music | str | |
preferred_api_video | str | |
skip_duplicates | bool | |
spotify_client_id | str | |
spotify_client_secret | str | |
subtitles_follow_video | bool | |
theme | str | UI theme (dark, light, or system to follow the OS on macOS) |
use_discord_rpc | bool | |
use_system_accent | bool | Use the system accent color instead of orange (macOS) |
video_format | str |
from_dictclassmethod
def from_dict(data: Dict[str, Any]) -> AppConfig:Create config from dictionary.
Parameters
| Name | Type | Description |
|---|---|---|
data | Dict[str, Any] |
to_dict
def to_dict() -> Dict[str, Any]:Convert config to dictionary.
SourceConfigManager
class ConfigManager(config_path: Optional[Path] = None)Configuration manager for S.O.K application.
Handles loading, saving, and accessing application configuration. Supports encrypted storage for sensitive fields (API keys) and runtime overrides from environment variables or constants.
Initialize configuration manager.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
config_path | Optional[Path] | None | Path to configuration file |
Attributes
| Name | Description |
|---|---|
SENSITIVE_FIELDS | List of field names that are encrypted. |
config | Current AppConfig instance. |
config_path | Path to the configuration JSON file. |
fernet | Fernet instance for encryption/decryption. |
env_locked
def env_locked(key: str) -> bool:Whether a key comes from the environment and wins over the settings.
The settings of the server show such a key as locked.
Parameters
| Name | Type | Description |
|---|---|---|
key | str |
from_env
def from_env(key: str) -> bool:Whether an environment variable gives this key (not a build key).
Parameters
| Name | Type | Description |
|---|---|---|
key | str |
get
def get(key: str, default: Any = None) -> Any:Get configuration value (Effective value). Priority: User Config > Runtime Overrides (Env/Constants), or Env > User Config > Constants when SOK_ENV_KEYS_WIN is set.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | str | Configuration key | |
default | Any | None | Default value if key doesn't exist |
Returns
AnyConfiguration value
get_available_languages
def get_available_languages() -> list[str]:Get list of available languages.
Returns
list[str]List of language codes
get_language_file
def get_language_file() -> Path:Get path to current language file.
Returns
PathPath to language JSON file
get_user_value
def get_user_value(key: str, default: Any = None) -> Any:Get value strictly from user configuration (no overrides). Used for UI display to avoid showing Dev keys.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | str | Configuration key | |
default | Any | None | Default value |
Returns
AnyUser saved value
load
def load() -> None:Load configuration from file, constants, or environment variables.
Priority for values:
- User configuration file (config.json)
- Compile-time constants (in production builds)
- Environment variables (.env file)
With SOK_ENV_KEYS_WIN set, the environment variables come first.
Sensitive fields are automatically decrypted if prefixed with 'ENC:'.
Sourceload_language
def load_language(language: Optional[str] = None) -> Dict[str, str]:Load translations for a language.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
language | Optional[str] | None | Language code; the one of the settings by default. |
Returns
Dict[str, str]Dictionary of translations
migrate_from_old_config
def migrate_from_old_config(old_config_path: Path) -> None:Migrate old configuration (meta.json) to new format.
Parameters
| Name | Type | Description |
|---|---|---|
old_config_path | Path | Path to old meta.json file |
reset
def reset() -> None:Reset configuration to default values.
Creates a new AppConfig with default values and saves it, effectively clearing all user customizations.
Sourcesave
def save() -> None:Save configuration to file.
Sensitive fields are automatically encrypted with 'ENC:' prefix before being written to the JSON file.
Sourceset
def set(key: str, value: Any) -> None:Set configuration value.
Parameters
| Name | Type | Description |
|---|---|---|
key | str | Configuration key |
value | Any | New value |
update
def update(**kwargs: Any) -> None:Update multiple configuration values.
Parameters
| Name | Type | Description |
|---|---|---|
**kwargs | Any | Key-value pairs to update |
Functions
config_dir_override
def config_dir_override() -> Optional[Path]:The folder given by SOK_CONFIG_DIR (/config in the Docker image), if set.
Sourcedata_dir
def data_dir() -> Path:Return the folder of the settings, their key and the rename history.
SOK_CONFIG_DIR when it is set, the data folder of the installation otherwise.
Sourceenv_keys_win
def env_keys_win() -> bool:Whether the keys of the environment win over those of the settings.
SOK_ENV_KEYS_WIN set to 1, true, yes or on (the Docker image sets it): a key given to the container is the one used. Without it, a key typed in the settings wins, as in the desktop app.
Sourceget_base_path
def get_base_path() -> Path:Get the base path for the application.
Returns
PathPath to executable directory if compiled (the user ApplicationPathSupport folder on macOS, the XDG data folder on Linux), or projectPathroot directory if running from source.
get_config_manager
def get_config_manager() -> ConfigManager:Get global configuration manager instance.
Returns
ConfigManagerConfigManager instance
get_local_key
def get_local_key() -> bytes:Retrieve or generate an encryption key specific to this installation.
The key is stored in .local.key next to config.json (data_dir()) and is hidden on Windows. If no key exists, a new one is generated using Fernet.
Returns
bytesThe local encryption key as bytes.
log_dir
def log_dir() -> Path:Return the folder of the log.
"logs" in SOK_CONFIG_DIR when it is set; otherwise ~/Library/Logs/S.O.K for the macOS app (its bundle is read-only), the XDG state folder for the Linux AppImage (read-only too), and "logs" next to the executable or in the repository.
Sourcereset_config_manager
def reset_config_manager() -> None:Reset global configuration manager instance.
Sourceresources_dir
def resources_dir() -> Path:Return the folder of the bundled resources (assets, translations).
Returns
PathContents/Resources/resources in the macOS app bundle, where thePathbundle signature seals them; the resources folder next to thePathexecutable in other compiled builds; the package folder otherwise.
xdg_base
def xdg_base(variable: str, fallback: str) -> Path:Return an XDG base directory (Linux).
Parameters
| Name | Type | Description |
|---|---|---|
variable | str | XDG variable, e.g. "XDG_DATA_HOME". |
fallback | str | Default relative to the home folder, e.g. ".local/share". Used when the variable is unset or not an absolute path, as the XDG Base Directory specification requires. |
xdg_dir
def xdg_dir(variable: str, fallback: str) -> Path:Return the S.O.K folder inside an XDG base directory (Linux).
Parameters
| Name | Type | Description |
|---|---|---|
variable | str | XDG variable, e.g. "XDG_DATA_HOME". |
fallback | str | Default relative to the home folder, e.g. ".local/share". |
Attributes
| Name | Value |
|---|---|
BASE_PATH | get_base_path() |
HAS_SECURE_CONSTANTS | True |
IS_COMPILED | '__compiled__' in globals() |
env_path | BASE_PATH / '.env' |
logger | logging.getLogger(__name__) |