mxivideo/python_core/utils/validators.py

114 lines
2.6 KiB
Python

"""
File validation utilities for MixVideo V2
"""
from pathlib import Path
from typing import Union
from ..config import settings
def validate_video_file(file_path: Union[str, Path]) -> bool:
"""
Validate if file is a supported video format.
Args:
file_path: Path to video file
Returns:
True if valid video file, False otherwise
"""
try:
path = Path(file_path)
# Check if file exists
if not path.exists():
return False
# Check if it's a file (not directory)
if not path.is_file():
return False
# Check file extension
if path.suffix.lower() not in settings.supported_video_formats:
return False
# Check file size (not empty)
if path.stat().st_size == 0:
return False
return True
except Exception:
return False
def validate_audio_file(file_path: Union[str, Path]) -> bool:
"""
Validate if file is a supported audio format.
Args:
file_path: Path to audio file
Returns:
True if valid audio file, False otherwise
"""
try:
path = Path(file_path)
# Check if file exists
if not path.exists():
return False
# Check if it's a file (not directory)
if not path.is_file():
return False
# Check file extension
if path.suffix.lower() not in settings.supported_audio_formats:
return False
# Check file size (not empty)
if path.stat().st_size == 0:
return False
return True
except Exception:
return False
def validate_image_file(file_path: Union[str, Path]) -> bool:
"""
Validate if file is a supported image format.
Args:
file_path: Path to image file
Returns:
True if valid image file, False otherwise
"""
try:
path = Path(file_path)
# Check if file exists
if not path.exists():
return False
# Check if it's a file (not directory)
if not path.is_file():
return False
# Check file extension
if path.suffix.lower() not in settings.supported_image_formats:
return False
# Check file size (not empty)
if path.stat().st_size == 0:
return False
return True
except Exception:
return False