Skip to content

utils ¤

TVSD Utilities, contains useful functions

dir_exists ¤

dir_exists(path: str, create_if_not: bool = False) -> bool

Check if a directory is mounted and exists.

Parameters:

  • path (str) –

    The path to check.

Returns:

  • bool ( bool ) –

    True if the directory exists and is mounted, False otherwise.

file_exists ¤

file_exists(file_path: str) -> bool

Checks if a file exists

Parameters:

  • file_path (str) –

    Path to file

Returns:

  • bool ( bool ) –

    True if file exists

file_exists_in_base ¤

file_exists_in_base(file_path: str) -> bool

Checks if a file exists in the base path

Parameters:

  • file_path (str) –

    Path to file

Returns:

  • bool ( bool ) –

    True if file exists

get_next_specials_index ¤

get_next_specials_index(show_dir: str) -> int

Gets the next specials index.

Parameters:

  • show_dir (str) –

    Path to show directory.

Returns:

  • int ( int ) –

    Next specials index.

is_video ¤

is_video(video_path: str) -> bool

Checks if a file is a video.

Parameters:

  • video_path (str) –

    Path to video file.

Returns:

  • bool ( bool ) –

    True if the file is a video, False otherwise.

mkdir_from_base ¤

mkdir_from_base(subdir: str) -> None

Creates a directory from media root.

Parameters:

  • subdir (str) –

    Directory to create.

mkdir_if_no ¤

mkdir_if_no(check_dir: str, recursive: bool = True) -> None

Creates a directory if it does not exist

Parameters:

  • check_dir (str) –

    Directory to check

relative_to_absolute_path ¤

relative_to_absolute_path(path: str) -> str

Converts a relative path to an absolute path

Parameters:

  • path (str) –

    Relative path

Returns:

  • str ( str ) –

    Absolute path

typer_easy_cli ¤

typer_easy_cli(func)

A decorator that takes a fully-annotated function and transforms it into a Typer command. Based on: https://github.com/tiangolo/typer/issues/336#issuecomment-1251698736

At the moment, the function needs to have only keywords at the moment, so this is ok:

def fun(*, par1: int, par2: float): ...

but this is NOT ok:

def fun(par1: int, par2: float): ...

video_in_dir ¤

video_in_dir(dir_path: str, recursive: bool = True) -> bool

Checks if a directory contains a video

Parameters:

  • dir_path (str) –

    Path to directory

  • recursive (bool, default: True ) –

    Whether to search recursively. Defaults to True.

Returns:

  • bool ( bool ) –

    True if directory contains a video