mirror of
https://github.com/onyx-and-iris/obsws-python.git
synced 2024-11-22 12:50:53 +00:00
parent
71c1e65483
commit
83afe31e04
@ -5,15 +5,6 @@ import logging
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
import tomllib
|
|
||||||
except ModuleNotFoundError:
|
|
||||||
import tomli as tomllib
|
|
||||||
except ModuleNotFoundError:
|
|
||||||
# ObsClient(host='...', port='...', password='...') must be used
|
|
||||||
tomllib = None
|
|
||||||
|
|
||||||
import websocket
|
import websocket
|
||||||
|
|
||||||
from .error import OBSSDKError
|
from .error import OBSSDKError
|
||||||
@ -25,12 +16,7 @@ class ObsClient:
|
|||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
defaultkwargs = {"host": "localhost", "port": 4455, "password": None, "subs": 0}
|
defaultkwargs = {"host": "localhost", "port": 4455, "password": None, "subs": 0}
|
||||||
if not any(key in kwargs for key in ("host", "port", "password")):
|
if not any(key in kwargs for key in ("host", "port", "password")):
|
||||||
if tomllib:
|
kwargs |= self._conn_from_toml()
|
||||||
kwargs |= self._conn_from_toml()
|
|
||||||
else:
|
|
||||||
raise ModuleNotFoundError(
|
|
||||||
"tomllib not installed; Perhaps use "
|
|
||||||
"ObsClient(host='...', port='...', password='...')")
|
|
||||||
kwargs = defaultkwargs | kwargs
|
kwargs = defaultkwargs | kwargs
|
||||||
for attr, val in kwargs.items():
|
for attr, val in kwargs.items():
|
||||||
setattr(self, attr, val)
|
setattr(self, attr, val)
|
||||||
@ -46,6 +32,10 @@ class ObsClient:
|
|||||||
self.server_hello = json.loads(self.ws.recv())
|
self.server_hello = json.loads(self.ws.recv())
|
||||||
|
|
||||||
def _conn_from_toml(self) -> dict:
|
def _conn_from_toml(self) -> dict:
|
||||||
|
try:
|
||||||
|
import tomllib
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
import tomli as tomllib
|
||||||
conn = {}
|
conn = {}
|
||||||
filepath = Path.cwd() / "config.toml"
|
filepath = Path.cwd() / "config.toml"
|
||||||
if filepath.exists():
|
if filepath.exists():
|
||||||
|
Loading…
Reference in New Issue
Block a user