sok.server.settings
The settings of S.O.K Server.
The settings shared with the desktop app (formats, file mode, behavior, language, API keys) stay in config.json through the ConfigManager, where the core reads them. The folders and the settings only the server has (SERVER_SETTINGS) are in the database. A key never leaves the server: the settings only say whether it is set, and whether an environment variable locks it.
InvalidSetting
class InvalidSetting(code: str, item: str)Bases: ValueError
A setting, key or folder that cannot be saved: code and what it is.
Parameters
| Name | Type | Description |
|---|---|---|
code | str | |
item | str |
Attributes
| Name |
|---|
code |
item |
LinkCheckdataclass
class LinkCheck( source: str, destination: str, problem: Optional[str] = None, tested: bool = True,)Whether a hard link works from a source to a destination.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | str | ||
destination | str | ||
problem | Optional[str] | None | |
tested | bool | True |
Attributes
| Name | Type |
|---|---|
destination | str |
problem | Optional[str] |
source | str |
tested | bool |
okproperty
bool
Settings
class Settings(db: Database, config: ConfigManager)Read and change the settings of the server.
Parameters
| Name | Type | Description |
|---|---|---|
db | Database | |
config | ConfigManager |
folders
def folders() -> Dict[str, List[str]]:The source folders, and the destination folders of each type.
Sourcekeys
def keys() -> List[Dict[str, Any]]:The services and their keys: set or not, locked or not; no value.
Sourcelink_checks
def link_checks() -> List[LinkCheck]:A check of every source with every destination folder.
Sourcenotifications
def notifications() -> Dict[str, Any]:What the settings show of the notifications: the addresses, and whether each secret and the script are set.
Sourcenotify_values
def notify_values() -> Dict[str, str]:The notification fields that are set, secrets included (for the server only).
Sourceservicesstaticmethod
def services() -> Dict[str, List[Dict[str, str]]]:The services a preferred_api_* setting can pick, per media type.
Sourceupdate
def update( values: Optional[Dict[str, Any]] = None, keys: Optional[Dict[str, str]] = None, folders: Optional[Dict[str, List[str]]] = None, notifications: Optional[Dict[str, str]] = None,) -> None:Change settings, keys (an empty value removes one), folders and notification fields (an empty value removes one).
Everything is checked first: all of it is saved, or nothing.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
values | Optional[Dict[str, Any]] | None | |
keys | Optional[Dict[str, str]] | None | |
folders | Optional[Dict[str, List[str]]] | None | |
notifications | Optional[Dict[str, str]] | None |
Raises
InvalidSettingThe first thing that cannot be saved.
value
def value(key: str) -> Any:One setting, as values() gives it.
Parameters
| Name | Type | Description |
|---|---|---|
key | str |
values
def values() -> Dict[str, Any]:UnreadableFolder
class UnreadableFolderBases: OSError
A folder that is missing, or that the server cannot read.
SourceFunctions
as_dict
def as_dict(check: LinkCheck) -> Dict[str, Any]:Parameters
| Name | Type | Description |
|---|---|---|
check | LinkCheck |
browse
def browse(path: Optional[str] = None) -> Dict[str, Any]:The subfolders of a folder of the server, for the folder browser of the settings: the browser cannot see the disks of the server.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
path | Optional[str] | None | An absolute path; the root of the file system when empty. |
Returns
Dict[str, Any]{"path", "parent" (None at the root), "folders": [{"name", "path"}]},Dict[str, Any]hidden folders left out, sorted by name, at most MAX_LISTED.
Raises
UnreadableFolderThe path is not an absolute folder, or cannot be read.
check_link
def check_link(source: str, destination: str) -> LinkCheck:Check that a hard link works from a source folder to a destination.
The two folders must be on the same device, which two Docker mounts are not, even on one disk; then a test link of a file of the source must work (FAT, exFAT and most network shares have no hard links).
Parameters
| Name | Type | Description |
|---|---|---|
source | str | |
destination | str |
Attributes
| Name | Type | Value |
|---|---|---|
AUTO_SORT_MINUTES | (1, 1440) | |
BOOL_SETTINGS | ('create_folders', 'skip_duplicates', 'backup_before_rename', 'subtitles_follow_video', 'download_posters') | |
DIFFERENT_DRIVES | 'different_drives' | |
FORMAT_SETTINGS | ('movie_format', 'video_format', 'music_format', 'book_format', 'game_format') | |
MAX_LISTED | 1000 | |
MAX_SCANNED | 1000 | |
MEDIA_TYPES | ('movies', 'tv', 'music', 'books', 'games') | |
MISSING_FOLDER | 'missing_folder' | |
NOTIFY_FIELDS | {'discord_url': True, 'webhook_url': True, 'jellyfin_url': False, 'jellyfin_key': True, 'plex_url': False, 'plex_token': True} | |
NOTIFY_URLS | ('discord_url', 'webhook_url', 'jellyfin_url', 'plex_url') | |
NO_HARD_LINKS | 'no_hard_links' | |
PREFERRED_API_SETTINGS | {'preferred_api_video': 'video', 'preferred_api_music': 'music', 'preferred_api_books': 'books', 'preferred_api_games': 'games'} | |
SCRIPT_VARIABLE | 'SOK_AFTER_RENAME' | |
SERVER_SETTINGS | Dict[str, Any] | {'auto_sort': False, 'auto_sort_minutes': 5} |
SETTINGS | ('language', 'file_mode') + BOOL_SETTINGS + FORMAT_SETTINGS + tuple(PREFERRED_API_SETTINGS) + tuple(SERVER_SETTINGS) | |
SOURCES | 'sources' |