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
| Name | Type | Description |
|---|---|---|
filename | str |
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
| Name | Type | Description |
|---|---|---|
fmt | str | The format, with {field} placeholders. |
values | dict[str, str] | The value of each field. |
Returns
strThe filled text, or "" if the format is not valid ("{", "{0}"…).
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
| Name | Type | Description |
|---|---|---|
name | str |
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
| Name | Type | Default | Description |
|---|---|---|---|
name | Optional[str] | None |
is_video_file
def is_video_file(filename: str) -> bool:Checks if a file is a video file
Parameters
| Name | Type | Description |
|---|---|---|
filename | str |
natural_key
def natural_key(path: Path) -> list:Sort key that orders numbers by value: "S01E2" before "S01E10".
Parameters
| Name | Type | Description |
|---|---|---|
path | Path | File path, compared case-insensitively. |