Skip to content

Instantly share code, notes, and snippets.

@ZiTAL
Last active January 26, 2024 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZiTAL/181749eb14543aed36c1ca5bffa6af36 to your computer and use it in GitHub Desktop.
Save ZiTAL/181749eb14543aed36c1ca5bffa6af36 to your computer and use it in GitHub Desktop.
python: Black Magic Videohub route out in
#!/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
@ZiTAL
Copy link
Author

ZiTAL commented Jan 26, 2024

For example: If BlackMagicVideohub is in a folder called lib

#!/usr/bin/python3
# -*- coding: utf-8 -*-

from lib.BlackMagicVideohub import BlackMagicVideohub

bm = BlackMagicVideohub({"host": "127.0.0.1", "port": 9990})
bm.route(10, 8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment