Skip to content

sok.server.watcher

The automatic sorting of S.O.K Server: the source folders are watched, and the new files are analyzed and renamed on their own.

When the auto_sort setting is on, the server looks at the files of the source folders every auto_sort_minutes. It reads the folders again instead of waiting for the events of the system, which most NAS shares and Docker mounts do not send. A file is taken once it is finished: same size and same date as at the check before, and not a download in progress (.part, .!qB, .crdownload…).

When finished files are new (or changed) since the last automatic sorting, an analysis runs, then the rows that are Ready are renamed, tab by tab, if all their files are finished. The rows to pick, the missing ones and the files to check wait in the tables. The analyses and renames it starts are marked "auto"; the history can undo them like the others.

Watcher

class Watcher(
db: Database,
settings: Settings,
scans: Scans,
renamer: Renamer,
jobs: Jobs,
events: EventBus,
clock: Callable[[], float] = time.monotonic,
)

Check the source folders and sort the new files, when auto_sort is on.

Parameters

NameTypeDefaultDescription
dbDatabase
settingsSettings
scansScans
renamerRenamer
jobsJobs
eventsEventBus
clockCallable[[], float]time.monotonic
Source

checkasync

async def check() -> bool:

Look at the source folders once; sort the new finished files.

Returns

  • boolWhether an automatic sorting ran.
Source

runasync

async def run() -> None:

Check the folders forever, every auto_sort_minutes (the task of the server).

Source

status

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

Whether the sorting is on, its last check and its last run.

Source

Functions

snapshot

def snapshot(sources: List[str]) -> Dict[str, Signature]:

The files of the source folders with their size and date, without hidden files and downloads in progress.

Parameters

NameTypeDescription
sourcesList[str]
Source

Attributes

NameValue
LAST_RUN'auto_sort_last_run'
PARTIAL_SUFFIXES('.part', '.partial', '.!qb', '.!ut', '.crdownload', '.download')
SignatureTuple[int, int]
TICK30
loggerlogging.getLogger(__name__)
Built with Kiln