blob: 834742028716c83720ef76539a10f45f198bd2ea (
plain)
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
46
47
48
49
50
51
52
53
54
55
|
import typing
from knowit.core import Configurable, Property
class BitRateMode(Configurable[str]):
"""Bit Rate mode property."""
class AudioCompression(Configurable[str]):
"""Audio Compression property."""
class AudioProfile(Configurable[str]):
"""Audio profile property."""
class AudioChannels(Property[int]):
"""Audio Channels property."""
ignored = {
'object based', # Dolby Atmos
}
def handle(self, value: typing.Union[int, str], context: typing.MutableMapping) -> typing.Optional[int]:
"""Handle audio channels."""
if isinstance(value, int):
return value
if value.lower() not in self.ignored:
try:
return int(value)
except ValueError:
self.report(value, context)
return None
class AudioCodec(Configurable[str]):
"""Audio codec property."""
@classmethod
def _extract_key(cls, value) -> str:
key = str(value).upper()
if key.startswith('A_'):
key = key[2:]
# only the first part of the word. E.g.: 'AAC LC' => 'AAC'
return key.split(' ')[0]
@classmethod
def _extract_fallback_key(cls, value, key) -> typing.Optional[str]:
if '/' in key:
return key.split('/')[0]
else:
return None
|