1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-26 09:37:25 +00:00
bazarr/libs/knowit/rules/audio/atmos.py
2020-03-18 15:33:54 -04:00

33 lines
1,005 B
Python

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from ...rule import Rule
class AtmosRule(Rule):
"""Atmos rule."""
@classmethod
def _redefine(cls, props, name, index):
actual = props.get(name)
if isinstance(actual, list):
value = actual[index]
if value is None:
del props[name]
else:
props[name] = value
def execute(self, props, pv_props, context):
"""Execute the rule against properties."""
codecs = props.get('codec') or []
# TODO: handle this properly
if 'atmos' in {codec.lower() for codec in codecs if codec}:
index = None
for i, codec in enumerate(codecs):
if codec and 'atmos' in codec.lower():
index = i
break
if index is not None:
for name in ('channels_count', 'sampling_rate'):
self._redefine(props, name, index)