Skip to content

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

NameTypeDefaultDescription
languagestr'en'UI language code
themestr'system' if sys.platform == 'darwin' else 'dark'UI theme (dark, light, or system to follow the OS on macOS)
use_system_accentboolFalseUse the system accent color instead of orange (macOS)
is_prodboolHAS_SECURE_CONSTANTSWhether the app is running in production (compiled) mode
api_key_tmdb_v4str''
api_key_tvdbstr''
api_key_omdbstr''
api_key_lastfmstr''
spotify_client_idstr''
spotify_client_secretstr''
google_books_api_keystr''
igdb_client_idstr''
igdb_client_secretstr''
api_key_rawgstr''
api_key_fanartstr''
client_id_discordstr''
default_video_pathstr''
default_music_pathstr''
default_books_pathstr''
default_games_pathstr''
create_foldersboolTrue
download_postersboolFalse
use_discord_rpcboolFalse
check_updatesboolTrue
video_formatstr'{title} S{season}E{episode} {episode_title}'
movie_formatstr'{title} ({year})'
music_formatstr'{artist} - {album}/{track} - {title}'
book_formatstr'{author} - {title} ({year})'
game_formatstr'{title} {tags}'
input_patternsDict[str, List[str]]dict()
backup_before_renameboolTrue
skip_duplicatesboolTrue
subtitles_follow_videoboolTrue
file_modestr'move'
log_operationsboolTrue
preferred_api_videostrSERVICE_TMDB
preferred_api_musicstrSERVICE_DEEZER
preferred_api_booksstrSERVICE_GOOGLE_BOOKS
preferred_api_gamesstrSERVICE_IGDB
Source

Attributes

NameTypeDescription
api_key_fanartstr
api_key_lastfmstr
api_key_omdbstr
api_key_rawgstr
api_key_tmdb_v4str
api_key_tvdbstr
backup_before_renamebool
book_formatstr
check_updatesbool
client_id_discordstr
create_foldersbool
default_books_pathstr
default_games_pathstr
default_music_pathstr
default_video_pathstr
download_postersbool
file_modestr
game_formatstr
google_books_api_keystr
igdb_client_idstr
igdb_client_secretstr
input_patternsDict[str, List[str]]
is_prodbool

Whether the app is running in production (compiled) mode

languagestr

UI language code

log_operationsbool
movie_formatstr
music_formatstr
preferred_api_booksstr
preferred_api_gamesstr
preferred_api_musicstr
preferred_api_videostr
skip_duplicatesbool
spotify_client_idstr
spotify_client_secretstr
subtitles_follow_videobool
themestr

UI theme (dark, light, or system to follow the OS on macOS)

use_discord_rpcbool
use_system_accentbool

Use the system accent color instead of orange (macOS)

video_formatstr

from_dictclassmethod

def from_dict(data: Dict[str, Any]) -> AppConfig:

Create config from dictionary.

Parameters

NameTypeDescription
dataDict[str, Any]
Source

to_dict

def to_dict() -> Dict[str, Any]:

Convert config to dictionary.

Source

ConfigManager

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

NameTypeDefaultDescription
config_pathOptional[Path]NonePath to configuration file
Source

Attributes

NameDescription
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

NameTypeDescription
keystr
Source

from_env

def from_env(key: str) -> bool:

Whether an environment variable gives this key (not a build key).

Parameters

NameTypeDescription
keystr
Source

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

NameTypeDefaultDescription
keystrConfiguration key
defaultAnyNoneDefault value if key doesn't exist

Returns

  • AnyConfiguration value
Source

get_available_languages

def get_available_languages() -> list[str]:

Get list of available languages.

Returns

  • list[str]List of language codes
Source

get_language_file

def get_language_file() -> Path:

Get path to current language file.

Returns

  • PathPath to language JSON file
Source

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

NameTypeDefaultDescription
keystrConfiguration key
defaultAnyNoneDefault value

Returns

  • AnyUser saved value
Source

load

def load() -> None:

Load configuration from file, constants, or environment variables.

Priority for values:

  1. User configuration file (config.json)
  2. Compile-time constants (in production builds)
  3. Environment variables (.env file)

With SOK_ENV_KEYS_WIN set, the environment variables come first.

Sensitive fields are automatically decrypted if prefixed with 'ENC:'.

Source

load_language

def load_language(language: Optional[str] = None) -> Dict[str, str]:

Load translations for a language.

Parameters

NameTypeDefaultDescription
languageOptional[str]NoneLanguage code; the one of the settings by default.

Returns

  • Dict[str, str]Dictionary of translations
Source

migrate_from_old_config

def migrate_from_old_config(old_config_path: Path) -> None:

Migrate old configuration (meta.json) to new format.

Parameters

NameTypeDescription
old_config_pathPathPath to old meta.json file
Source

reset

def reset() -> None:

Reset configuration to default values.

Creates a new AppConfig with default values and saves it, effectively clearing all user customizations.

Source

save

def save() -> None:

Save configuration to file.

Sensitive fields are automatically encrypted with 'ENC:' prefix before being written to the JSON file.

Source

set

def set(key: str, value: Any) -> None:

Set configuration value.

Parameters

NameTypeDescription
keystrConfiguration key
valueAnyNew value
Source

update

def update(**kwargs: Any) -> None:

Update multiple configuration values.

Parameters

NameTypeDescription
**kwargsAnyKey-value pairs to update
Source

Functions

config_dir_override

def config_dir_override() -> Optional[Path]:

The folder given by SOK_CONFIG_DIR (/config in the Docker image), if set.

Source

data_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.

Source

env_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.

Source

get_base_path

def get_base_path() -> Path:

Get the base path for the application.

Returns

  • PathPath to executable directory if compiled (the user Application
  • PathSupport folder on macOS, the XDG data folder on Linux), or project
  • Pathroot directory if running from source.
Source

get_config_manager

def get_config_manager() -> ConfigManager:

Get global configuration manager instance.

Returns

Source

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.
Source

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.

Source

reset_config_manager

def reset_config_manager() -> None:

Reset global configuration manager instance.

Source

resources_dir

def resources_dir() -> Path:

Return the folder of the bundled resources (assets, translations).

Returns

  • PathContents/Resources/resources in the macOS app bundle, where the
  • Pathbundle signature seals them; the resources folder next to the
  • Pathexecutable in other compiled builds; the package folder otherwise.
Source

xdg_base

def xdg_base(variable: str, fallback: str) -> Path:

Return an XDG base directory (Linux).

Parameters

NameTypeDescription
variablestrXDG variable, e.g. "XDG_DATA_HOME".
fallbackstrDefault 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.
Source

xdg_dir

def xdg_dir(variable: str, fallback: str) -> Path:

Return the S.O.K folder inside an XDG base directory (Linux).

Parameters

NameTypeDescription
variablestrXDG variable, e.g. "XDG_DATA_HOME".
fallbackstrDefault relative to the home folder, e.g. ".local/share".
Source

Attributes

NameValue
BASE_PATHget_base_path()
HAS_SECURE_CONSTANTSTrue
IS_COMPILED'__compiled__' in globals()
env_pathBASE_PATH / '.env'
loggerlogging.getLogger(__name__)
Built with Kiln