Skip to content

sok.core.utils

General utility functions.

Provides common utility functions for filename formatting, episode information extraction, file type detection, and logging setup.

Functions

extract_episode_info

def extract_episode_info(filename: str) -> Optional[dict]:

Extracts episode information from a filename

Parameters

NameTypeDescription
filenamestr
Source

fill_format

def fill_format(fmt: str, values: dict[str, str]) -> str:

Fill a name format of the settings, such as "{author} - {title} ({year})".

A value that is empty or unknown is left out with what it leaves around it: without a year, the example gives "Author - Title".

Parameters

NameTypeDescription
fmtstrThe format, with {field} placeholders.
valuesdict[str, str]The value of each field.

Returns

  • strThe filled text, or "" if the format is not valid ("{", "{0}"…).
Source

format_name

def format_name(name: str) -> str:

Formats a file or folder name: no forbidden character, single spaces, and no dot or space at the end of the name or before its extension.

A title that ends with "..." no longer gives "Bag....mkv", and a folder no longer ends with a dot, which Windows refuses.

Parameters

NameTypeDescription
namestr
Source

get_logger

def get_logger(name: Optional[str] = None) -> logging.Logger:

Return a logger with a null handler to avoid "No handler" warnings if not configured.

Parameters

NameTypeDefaultDescription
nameOptional[str]None
Source

is_video_file

def is_video_file(filename: str) -> bool:

Checks if a file is a video file

Parameters

NameTypeDescription
filenamestr
Source

natural_key

def natural_key(path: Path) -> list:

Sort key that orders numbers by value: "S01E2" before "S01E10".

Parameters

NameTypeDescription
pathPathFile path, compared case-insensitively.
Source
Built with Kiln