first commit
This commit is contained in:
117
python_core/utils/validators.py
Normal file
117
python_core/utils/validators.py
Normal file
@@ -0,0 +1,117 @@
|
||||
"""
|
||||
File validation utilities for MixVideo V2
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user