sok.server.notify
The notifications of S.O.K Server, after each rename that moved files.
Each target set in the settings gets the rename, by hand or automatic:
- Discord: a message to a webhook of a channel;
- Jellyfin and Plex: a refresh of their libraries;
- a webhook: the rename as JSON (RenameEvent), for Home Assistant, n8n…;
- a script: the command of SOK_AFTER_RENAME, run without a shell, with the JSON on its standard input and SOK_EVENT, SOK_MEDIA_TYPE, SOK_RENAMED and SOK_AUTO in its environment.
A target that fails is logged and does not stop the others, nor the rename.
Notifier
class Notifier( settings: Settings, config: ConfigManager, request: Request = http_request,)Send a rename to every target of the settings.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
settings | Settings | ||
config | ConfigManager | ||
request | Request | http_request |
renamedasync
async def renamed(event: Dict[str, Any]) -> Dict[str, Optional[str]]:Send a rename to every target set.
Parameters
| Name | Type | Description |
|---|---|---|
event | Dict[str, Any] | {"media_type", "auto", "renamed", "files": [{"from", "to"}]}; "event" and "date" are added. |
Returns
Dict[str, Optional[str]]For each target set, None when it worked, else why it failed.
renamed_later
def renamed_later(event: Dict[str, Any]) -> None:Send a rename in the background (called by the Renamer).
Parameters
| Name | Type | Description |
|---|---|---|
event | Dict[str, Any] |
testasync
async def test(target: str) -> Optional[str]:Send a test to one target; None when it worked, else why not.
Parameters
| Name | Type | Description |
|---|---|---|
target | str |
Raises
ValueErrorAn unknown target.
NotifyError
class NotifyErrorBases: Exception
A target that did not take the notification: why, in a few words.
SourceFunctions
http_requestasync
async def http_request( method: str, url: str, headers: Dict[str, str], body: Optional[Any],) -> int:Send a request; returns its status.
Parameters
| Name | Type | Description |
|---|---|---|
method | str | |
url | str | |
headers | Dict[str, str] | |
body | Optional[Any] |
Attributes
| Name | Value |
|---|---|
MAX_LISTED | 10 |
Request | Callable[[str, str, Dict[str, str], Optional[Any]], Awaitable[int]] |
SCRIPT_TIMEOUT | 300 |
TAB_NAMES | {'movies': ('movies', 'Movies'), 'tv': ('tv_shows', 'TV Shows'), 'music': ('music', 'Music'), 'books': ('books', 'Books'), 'games': ('games', 'Games')} |
TARGETS | ('discord', 'jellyfin', 'plex', 'webhook', 'script') |
TIMEOUT | 15 |
logger | logging.getLogger(__name__) |