Spaces:
Sleeping
Sleeping
| """Audio entity.""" | |
| from dataclasses import dataclass | |
| from typing import Optional | |
| from ..value_objects.audio_format import AudioFormat | |
| from ..value_objects.audio_quality import AudioQuality | |
| from ..value_objects.file_size import FileSize | |
| class Audio: | |
| """Entity representing an audio file.""" | |
| filename: str | |
| file_path: str | |
| format: AudioFormat | |
| quality: AudioQuality | |
| size: Optional[FileSize] = None | |
| duration: Optional[float] = None | |
| bitrate: Optional[str] = None | |
| def get_mime_type(self) -> str: | |
| """Get MIME type for this audio file.""" | |
| return self.format.mime_type | |
| def get_full_filename(self) -> str: | |
| """Get filename with correct extension.""" | |
| base_name = self.filename | |
| if not base_name.endswith(self.format.extension): | |
| base_name = f"{base_name}{self.format.extension}" | |
| return base_name | |
| def create_from_extraction(cls, source_video: 'Video', file_path: str, | |
| format: AudioFormat, quality: AudioQuality, | |
| size: Optional[int] = None) -> 'Audio': | |
| """Create Audio from extraction process.""" | |
| filename = f"{source_video.get_filename_without_extension()}{format.extension}" | |
| return cls( | |
| filename=filename, | |
| file_path=file_path, | |
| format=format, | |
| quality=quality, | |
| size=FileSize(size) if size else None | |
| ) |