New archi: domain driven development
Working but need to check out code
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
"""Subtitle domain value objects."""
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
|
||||
from ..shared.exceptions import ValidationError
|
||||
|
||||
|
||||
class Language(Enum):
|
||||
"""Supported subtitle languages."""
|
||||
ENGLISH = "en"
|
||||
FRENCH = "fr"
|
||||
SPANISH = "es"
|
||||
GERMAN = "de"
|
||||
ITALIAN = "it"
|
||||
PORTUGUESE = "pt"
|
||||
RUSSIAN = "ru"
|
||||
JAPANESE = "ja"
|
||||
KOREAN = "ko"
|
||||
CHINESE = "zh"
|
||||
ARABIC = "ar"
|
||||
|
||||
@classmethod
|
||||
def from_code(cls, code: str) -> "Language":
|
||||
"""
|
||||
Get language from ISO 639-1 code.
|
||||
|
||||
Args:
|
||||
code: Two-letter language code
|
||||
|
||||
Returns:
|
||||
Language enum value
|
||||
|
||||
Raises:
|
||||
ValidationError: If code is not supported
|
||||
"""
|
||||
code_lower = code.lower()
|
||||
for lang in cls:
|
||||
if lang.value == code_lower:
|
||||
return lang
|
||||
raise ValidationError(f"Unsupported language code: {code}")
|
||||
|
||||
|
||||
class SubtitleFormat(Enum):
|
||||
"""Supported subtitle formats."""
|
||||
SRT = "srt" # SubRip
|
||||
ASS = "ass" # Advanced SubStation Alpha
|
||||
SSA = "ssa" # SubStation Alpha
|
||||
VTT = "vtt" # WebVTT
|
||||
SUB = "sub" # MicroDVD
|
||||
|
||||
@classmethod
|
||||
def from_extension(cls, extension: str) -> "SubtitleFormat":
|
||||
"""
|
||||
Get format from file extension.
|
||||
|
||||
Args:
|
||||
extension: File extension (with or without dot)
|
||||
|
||||
Returns:
|
||||
SubtitleFormat enum value
|
||||
|
||||
Raises:
|
||||
ValidationError: If extension is not supported
|
||||
"""
|
||||
ext = extension.lower().lstrip('.')
|
||||
for fmt in cls:
|
||||
if fmt.value == ext:
|
||||
return fmt
|
||||
raise ValidationError(f"Unsupported subtitle format: {extension}")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TimingOffset:
|
||||
"""
|
||||
Value object representing subtitle timing offset in milliseconds.
|
||||
|
||||
Used for synchronizing subtitles with video.
|
||||
"""
|
||||
milliseconds: int
|
||||
|
||||
def __post_init__(self):
|
||||
"""Validate timing offset."""
|
||||
if not isinstance(self.milliseconds, int):
|
||||
raise ValidationError(f"Timing offset must be an integer, got {type(self.milliseconds)}")
|
||||
|
||||
def to_seconds(self) -> float:
|
||||
"""Convert to seconds."""
|
||||
return self.milliseconds / 1000.0
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.milliseconds}ms"
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"TimingOffset({self.milliseconds})"
|
||||
Reference in New Issue
Block a user