Last active
January 26, 2024 11:00
-
-
Save ZiTAL/181749eb14543aed36c1ca5bffa6af36 to your computer and use it in GitHub Desktop.
python: Black Magic Videohub route out in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
# based on: https://github.com/harmanhobbit/smarthubctl/blob/main/smarthubctl.py | |
import socket | |
class BlackMagicVideohub: | |
def __init__(self, config): | |
self.config = config | |
self.connect() | |
def connect(self): | |
try: | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((self.config['host'], self.config['port'])) | |
self.instance = s | |
return True | |
except: | |
return False | |
def isConnected(self): | |
try: | |
code = self.instance.getsockopt(self.instance.SOL_SOCKET, self.instance.SO_ERROR) | |
if code == 0: | |
return True | |
else: | |
return False | |
except: | |
return False | |
def getRoute(self, output, input): | |
str = f"VIDEO OUTPUT ROUTING:\n{output} {input}\n\n" | |
return str | |
def route(self, _out, _in): | |
if self.isConnected() == False: | |
self.connect() | |
r = self.getRoute(_out, _in).encode() | |
s = self.instance.send(r) | |
if s == len(r): | |
return True | |
else: | |
return False | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For example: If BlackMagicVideohub is in a folder called lib