File size: 1,656 Bytes
92fd1a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Audio quality value object."""
from dataclasses import dataclass
from typing import Dict, Any

from ..exceptions.domain_exceptions import InvalidQualityLevelError

@dataclass(frozen=True)
class AudioQuality:
    """Value object representing audio quality level."""
    value: str
    
    LEVELS = {
        'high': {'priority': 3, 'description': 'Best quality, larger file size'},
        'medium': {'priority': 2, 'description': 'Balanced quality and file size'},
        'low': {'priority': 1, 'description': 'Smaller file size, acceptable quality'}
    }
    
    def __post_init__(self):
        if self.value.lower() not in self.LEVELS:
            raise InvalidQualityLevelError(self.value)
        
        # Normalize to lowercase
        object.__setattr__(self, 'value', self.value.lower())
    
    @property
    def priority(self) -> int:
        """Get numeric priority (higher is better quality)."""
        return self.LEVELS[self.value]['priority']
    
    @property
    def description(self) -> str:
        """Get human-readable description."""
        return self.LEVELS[self.value]['description']
    
    def get_settings_for_format(self, audio_format: 'AudioFormat', 
                                quality_presets: Dict[str, Dict[str, Dict[str, Any]]]) -> Dict[str, Any]:
        """Get quality settings for specific audio format."""
        return quality_presets.get(audio_format.value, {}).get(self.value, {})
    
    def __str__(self) -> str:
        return self.value
    
    def __lt__(self, other: 'AudioQuality') -> bool:
        """Compare quality levels by priority."""
        return self.priority < other.priority