diff options
Diffstat (limited to 'switcher.py')
| -rw-r--r-- | switcher.py | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/switcher.py b/switcher.py index 4262846..595962a 100644 --- a/switcher.py +++ b/switcher.py @@ -1,20 +1,17 @@ import logging import PyATEMMax -from PyATEMMax.ATEMProtocolEnums import ATEMVideoModeFormats, ATEMTransitionStyles +from PyATEMMax.ATEMProtocolEnums import (ATEMTransitionStyles, + ATEMVideoModeFormats) -VIDEO_FORMATS = { - f[1:] - for f in dir(ATEMVideoModeFormats) - if f.startswith('f') -} +VIDEO_FORMATS = {f[1:] for f in dir(ATEMVideoModeFormats) if f.startswith("f")} class PyATEMSwitcher: def __init__(self, config): self.atem = PyATEMMax.ATEMMax() - self.config = config.get('atem', {}) - self.log = logging.getLogger('Switcher') + self.config = config.get("atem", {}) + self.log = logging.getLogger("Switcher") self._connect_subscribers = [] self._connect_attempt_subscribers = [] @@ -41,61 +38,61 @@ class PyATEMSwitcher: ) def _on_connect(self, params): - self.log.debug(f'_on_connect({repr(params)})') + self.log.debug(f"_on_connect({repr(params)})") self._push_config() for callback in self._connect_subscribers: callback(params) def _on_connect_attempt(self, params): - self.log.debug(f'_on_connect_attempt({repr(params)})') + self.log.debug(f"_on_connect_attempt({repr(params)})") for callback in self._connect_attempt_subscribers: callback(params) def _on_disconnect(self, params): - self.log.debug(f'_on_disconnect({repr(params)})') + self.log.debug(f"_on_disconnect({repr(params)})") for callback in self._disconnect_subscribers: callback(params) def _on_receive(self, params): - self.log.debug(f'_on_receive({repr(params)})') + self.log.debug(f"_on_receive({repr(params)})") for callback in self._receive_subscribers: callback(params) def _push_config(self): - conf = self.config.get('settings', {}) + conf = self.config.get("settings", {}) # TODO media upload to MP1 - if 'video_mode' in self.config: + if "video_mode" in self.config: video_mode = getattr( ATEMVideoModeFormats, - 'f'+self.config['video_mode'], + "f" + self.config["video_mode"], ) if self.atem.videoMode.format != video_mode: self.atem.setVideoModeFormat(video_mode) - - if conf.get('inputs', None): - for key, name in conf['inputs'].items(): + + if conf.get("inputs", None): + for key, name in conf["inputs"].items(): input_number = getattr(self.atem.atem.videoSources, key) self.log.debug(f"setting input {input_number} to name '{name}'") self.atem.setInputLongName(input_number, name) self.atem.setInputShortName(input_number, name[0:3]) def _validate_config(self): - if 'ip' not in self.config: - raise KeyError('Please set ATEM IP in config!') + if "ip" not in self.config: + raise KeyError("Please set ATEM IP in config!") if ( - 'video_mode' in self.config - and self.config['video_mode'] not in VIDEO_FORMATS + "video_mode" in self.config + and self.config["video_mode"] not in VIDEO_FORMATS ): raise ValueError( f'ATEM video_mode {self.config["video_mode"]} ' - 'is not a valid video mode, must be one of: ' + "is not a valid video mode, must be one of: " f'{", ".join(sorted(VIDEO_FORMATS))}' ) def connect(self): - self.log.info('Initiating connection to switcher') - self.atem.connect(self.config['ip']) + self.log.info("Initiating connection to switcher") + self.atem.connect(self.config["ip"]) def disconnect(self): self.atem.disconnect() @@ -113,7 +110,7 @@ class PyATEMSwitcher: self._receive_subscribers.append(callback) def trans(self, input): - self.log.debug(f'hehehehe trans({repr(input)})') + self.log.debug(f"hehehehe trans({repr(input)})") self.atem.setPreviewInputVideoSource( ATEMTransitionStyles.mix, input, |
