validators
Contains functions to validate user input and other data.
positive_int
Return a positive integer from a float, integer or string.
Args:
`n` (float | int | str): The number to validate.
Returns:
`int`: The number as an integer if positive.
Raises:
`ValidationError`: If the number is not a positive integer.
Source code in videoxt/validators.py
positive_float
Return a positive float from a float, integer or string.
Args:
`n` (float | int | str): The number to validate.
Returns:
`float`: The number as a float if positive.
Raises:
`ValidationError`: If the number is not a positive float.
Source code in videoxt/validators.py
non_negative_int
Return a non-negative integer from a float, integer or string.
Args:
`n` (float | int | str): The number to validate.
Returns:
`int`: The number as an integer if non-negative.
Raises:
`ValidationError`: If the number is not a non-negative integer.
Source code in videoxt/validators.py
non_negative_float
Return a non-negative float from a float, integer or string.
Args:
`n` (float | int | str): The number to validate.
Returns:
`float`: The number as a float if non-negative.
Raises:
`ValidationError`: If the number is not a non-negative float.
Source code in videoxt/validators.py
valid_dir
Validate a path is a directory and exists and return it.
Args:
`directory` (Path | str): The directory to validate.
Returns:
`Path`: The directory as a Path object if valid.
Raises:
`ValidationError`: If the path is not a directory or does not exist.
Source code in videoxt/validators.py
valid_filepath
Validate a path is a file and exists and return it.
Args:
`filepath` (Path | str):
The filepath to validate.
`is_video` (bool) :
If True, the filepath is checked against a set of supported video file
suffixes.
Returns:
`Path`: The filepath as a Path object if it is a file and exists.
Raises:
`ValidationError`: If the path is not a file or does not exist.
Source code in videoxt/validators.py
valid_filename
Validate a filename does not contain invalid characters and return it.
In the context of videoxt, a filename refers to a Path().stem.
Args:
`filename` (str): The filename to validate.
Returns:
`str`: The filename if it does not contain invalid characters.
Raises:
`ValidationError`: If the filename is None, empty or contains invalid chars.
Source code in videoxt/validators.py
valid_timestamp
Validate a timestamp is in the correct format and return it if valid.
In the context of videoxt a timestamp is one typically seen during playback on
video sharing or streaming platforms. Microseconds are truncated.
Valid: M:SS, MM:SS, H:MM:SS, HH:MM:SS.
Invalid: S, SS, H:M:S, values greater than 59 for hours, minutes or seconds.
Args:
`timestamp` (str): The timestamp to validate.
Returns:
`str`: The timestamp if valid.
Raises:
`ValidationError`:
If the timestamp is None, empty, or does not match the regex pattern.
Source code in videoxt/validators.py
valid_start_timestamp
Validate a start timestamp is in the correct format and return it if valid.
Valid: M:SS, MM:SS, H:MM:SS, HH:MM:SS.
Invalid: S, SS, H:M:S, values greater than 59 for hours, minutes or seconds.
See valid_timestamp for more information on how timestamps are validated.
Args:
`start_timestamp` (str) : The timestamp to validate (Ex: '12:34').
Returns:
`str`: The timestamp as a string if valid.
Source code in videoxt/validators.py
valid_stop_timestamp
Validate a stop timestamp is in the correct format and return it if valid.
Valid: M:SS, MM:SS, H:MM:SS, HH:MM:SS.
Invalid: S, SS, H:M:S, values greater than 59 for hours, minutes or seconds.
See valid_timestamp for more information on how timestamps are validated.
Args:
`stop_timestamp` (str): The timestamp to validate (Ex: '12:34').
Returns:
`str`: The timestamp as a string if valid.
Source code in videoxt/validators.py
valid_start_time
Validate the start time param is a not negative or a properly formatted timestamp.
If start_time is str it is expected to be a timestamp (ex: 'HH:MM:SS') and is
returned slightly modified if valid (microseconds are truncated, if any). Otherwise,
a number must be greater than or equal to 0 and is returned as a float if valid.
Args:
`start_time` (float | int | str): The start time request parameter.
Returns:
`float | str`: The passed in, slightly modified start time if valid.
Raises:
`ValidationError`:
If start time an unaccepted timestamp string, not 0 or greater, or None.
Source code in videoxt/validators.py
valid_stop_time
Validate the stop time param is a positive number or a properly formatted timestamp.
If stop_time is str it is expected to be a timestamp (ex: 'HH:MM:SS') and is
returned slightly modified if valid (microseconds are truncated, if any). Otherwise,
a number must be greater than 0 and is returned as a float if valid.
Args:
`stop_time` (float | int | str): The stop time request parameter.
Returns:
`float | str`: The passed in, slightly modified stop time if valid.
Raises:
`ValidationError`:
If stop time an unaccepted timestamp string, not greater than 0, or None.
Source code in videoxt/validators.py
valid_extraction_range
Validate the extraction range against the video's duration and return it if valid.
Args:
`start` (float):
Extraction start second.
`stop` (float):
Extraction stop second.
`duration` (float):
Duration of the video in seconds.
Returns:
`Tuple[float, float, float]`:
The start, stop and duration if valid (start, stop, duration).
Raises:
`ValidationError`:
- If the start time is greater than or equal to the video duration.
- If the stop time is less than or equal to the start time.
Source code in videoxt/validators.py
valid_dimensions
Validate values in a dimensions tuple are positive integers and return it.
Args:
`dimensions` (tuple[int, int]): The dimensions to validate.
Returns:
`tuple[int, int]`: The dimensions if both integers are positive.
Raises:
`ValidationError`:
If the length of the tuple isn't 2 or one or more of the values are not
positive integers
Source code in videoxt/validators.py
valid_rotate_value
Validate a rotate value is either 0, 90, 180 or 270.
Args:
`n` (float | int | str): The rotate value to validate.
Returns:
`int`: The rotate value if 0, 90, 180, or 270.
Raises:
`ValidationError`: If the rotate value is invalid.
Source code in videoxt/validators.py
valid_audio_format
Validate audio format is supported by videoxt and return it if so.
Input is converted to lowercase and stripped of any leading periods. Mp3 and
.MP3 would both be considered valid and returned as mp3.
See supported formats here: videoxt.constants.SUPPORTED_AUDIO_FORMATS.
Args:
`audio_format` (str): The audio format to validate.
Returns:
`str`: The audio format if supported.
Raises:
`ValidationError`: If the audio format is not supported.
Source code in videoxt/validators.py
valid_image_format
Validate image format is supported by videoxt and return it if so.
Input is converted to lowercase and stripped of any leading periods. jpG and
.JPG would both be considered valid and returned as jpg.
See supported formats here: videoxt.constants.SUPPORTED_IMAGE_FORMATS.
Args:
`image_format` (str): The image format to validate.
Returns:
`str`: The image format if valid.
Raises:
`ValidationError`: If the image format is not supported.
Source code in videoxt/validators.py
valid_volume
Validate and return non-negative float audio volume. If input is negative, set to 0.
Args:
`volume` (float | int | str): The volume to validate.
Returns:
`float`: The volume as a float if valid.
Raises:
`ValidationError`: If the volume is None.
Source code in videoxt/validators.py
valid_video_file_suffix
Validate suffix provided is supported by videoxt and return it.
Input is converted to lowercase and stripped of any leading periods. Mp4 and
.MP4 would both be considered valid and returned as mp4.
Args:
`suffix` (str): The suffix to validate.
Returns:
`str`: The suffix if valid.
Raises:
`ValidationError`: If the video format is not supported.
Source code in videoxt/validators.py
valid_fps
Validate and return a positive float fps.
Args:
`fps` (float | int | str): The fps to validate.
Returns:
`float`: The fps as a float if valid.
Raises:
`ValidationError`: If the fps is None or not a positive float.
Source code in videoxt/validators.py
valid_dimensions_str
Validate and return a tuple of positive integers from a string of dimensions.
Args:
`dimensions` (str): The dimensions to validate.
Returns:
`tuple[int, int]`: The dimensions as a tuple of integers if valid.
Raises:
`ValidationError`: If the dimensions are None, empty, or not in this format:
'WxH' (Ex: '1920x1080').
Source code in videoxt/validators.py
valid_resize
Validate and return a positive float resize value.
Args:
`resize` (float | int | str): The resize value to validate.
Returns:
`float`: The resize value as a float if valid.
Raises:
`ValidationError`: If the resize value is None or not a positive float.
Source code in videoxt/validators.py
valid_speed
Validate and return a positive float speed value.
Args:
`speed` (float | int | str): The speed value to validate.
Returns:
`float`: The speed value as a float if valid.
Raises:
`ValidationError`: If the speed value is None or not a positive float.
Source code in videoxt/validators.py
valid_capture_rate
Validate and return a positive integer capture rate.
Args:
`capture_rate` (float | int | str): The capture rate to validate.
Returns:
`int`: The capture rate as an integer if valid.
Raises:
`ValidationError`: If the capture rate is None or not a positive integer.