Skip to content

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

NameTypeDescription
codestr
itemstr
Source

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

NameTypeDefaultDescription
sourcestr
destinationstr
problemOptional[str]None
testedboolTrue
Source

Attributes

NameType
destinationstr
problemOptional[str]
sourcestr
testedbool

okproperty

bool

Settings

class Settings(db: Database, config: ConfigManager)

Read and change the settings of the server.

Parameters

NameTypeDescription
dbDatabase
configConfigManager
Source

folders

def folders() -> Dict[str, List[str]]:

The source folders, and the destination folders of each type.

Source

keys

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

The services and their keys: set or not, locked or not; no value.

Source
def link_checks() -> List[LinkCheck]:

A check of every source with every destination folder.

Source

notifications

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

What the settings show of the notifications: the addresses, and whether each secret and the script are set.

Source

notify_values

def notify_values() -> Dict[str, str]:

The notification fields that are set, secrets included (for the server only).

Source

servicesstaticmethod

def services() -> Dict[str, List[Dict[str, str]]]:

The services a preferred_api_* setting can pick, per media type.

Source

update

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

NameTypeDefaultDescription
valuesOptional[Dict[str, Any]]None
keysOptional[Dict[str, str]]None
foldersOptional[Dict[str, List[str]]]None
notificationsOptional[Dict[str, str]]None

Raises

Source

value

def value(key: str) -> Any:

One setting, as values() gives it.

Parameters

NameTypeDescription
keystr
Source

values

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

UnreadableFolder

class UnreadableFolder

Bases: OSError

A folder that is missing, or that the server cannot read.

Source

Functions

as_dict

def as_dict(check: LinkCheck) -> Dict[str, Any]:

Parameters

NameTypeDescription
checkLinkCheck
Source

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

NameTypeDefaultDescription
pathOptional[str]NoneAn 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

Source
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

NameTypeDescription
sourcestr
destinationstr
Source

Attributes

NameTypeValue
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_LISTED1000
MAX_SCANNED1000
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')
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_SETTINGSDict[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'
Built with Kiln