Skip to content

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

NameTypeDefaultDescription
settingsSettings
configConfigManager
requestRequesthttp_request
Source

renamedasync

async def renamed(event: Dict[str, Any]) -> Dict[str, Optional[str]]:

Send a rename to every target set.

Parameters

NameTypeDescription
eventDict[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.
Source

renamed_later

def renamed_later(event: Dict[str, Any]) -> None:

Send a rename in the background (called by the Renamer).

Parameters

NameTypeDescription
eventDict[str, Any]
Source

testasync

async def test(target: str) -> Optional[str]:

Send a test to one target; None when it worked, else why not.

Parameters

NameTypeDescription
targetstr

Raises

  • ValueErrorAn unknown target.
Source

NotifyError

class NotifyError

Bases: Exception

A target that did not take the notification: why, in a few words.

Source

Functions

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

NameTypeDescription
methodstr
urlstr
headersDict[str, str]
bodyOptional[Any]
Source

Attributes

NameValue
MAX_LISTED10
RequestCallable[[str, str, Dict[str, str], Optional[Any]], Awaitable[int]]
SCRIPT_TIMEOUT300
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')
TIMEOUT15
loggerlogging.getLogger(__name__)
Built with Kiln