Compare commits

..

No commits in common. "822bdfb60dc536073d61084da3a0e84cb7ed206d" and "e92c3b2e6f4361cb3e9cb29975d64f3723cfc261" have entirely different histories.

5 changed files with 12 additions and 39 deletions

View File

@ -1,6 +1,5 @@
[![PyPI version](https://badge.fury.io/py/streamlabsio.svg)](https://badge.fury.io/py/streamlabsio) [![PyPI version](https://badge.fury.io/py/streamlabsio.svg)](https://badge.fury.io/py/streamlabsio)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/onyx-and-iris/streamlabs-socketio-py/blob/dev/LICENSE) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/onyx-and-iris/streamlabs-socketio-py/blob/dev/LICENSE)
[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/) [![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
@ -71,10 +70,6 @@ The following keyword arguments may be passed:
- `token`: str Streamlabs SocketIO api token. - `token`: str Streamlabs SocketIO api token.
- `raw`: boolean=False Receive raw data messages as json objects. - `raw`: boolean=False Receive raw data messages as json objects.
The following attribute is available:
- `raw`: boolean Toggle raw mode at runtime.
### Attributes ### Attributes
For event data you may inspect the available attributes using `attrs()`. For event data you may inspect the available attributes using `attrs()`.
@ -88,7 +83,6 @@ def on_twitch_event(event, data):
### Errors ### Errors
- `SteamlabsSIOError`: Base StreamlabsSIO error class
- `SteamlabsSIOConnectionError`: Exception raised when connection errors occur - `SteamlabsSIOConnectionError`: Exception raised when connection errors occur
### Logging ### Logging

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "streamlabsio" name = "streamlabsio"
version = "1.1.1" version = "1.0.2"
description = "Get real time Twitch/Youtube events through Streamlabs SocketIO API" description = "Get real time Twitch/Youtube events through Streamlabs SocketIO API"
authors = ["onyx-and-iris <code@onyxandiris.online>"] authors = ["onyx-and-iris <code@onyxandiris.online>"]
license = "MIT" license = "MIT"

View File

@ -1,8 +1,7 @@
import subprocess import subprocess
import sys
from pathlib import Path from pathlib import Path
def ex_debug(): def ex_debug():
scriptpath = Path.cwd() / "examples" / "debug" / "." path = Path.cwd() / "examples" / "debug" / "."
subprocess.run([sys.executable, str(scriptpath)]) subprocess.run(["py", str(path)])

View File

@ -33,26 +33,8 @@ class Client:
raise SteamlabsSIOConnectionError( raise SteamlabsSIOConnectionError(
"no connection could be established to the Streamlabs SIO server" "no connection could be established to the Streamlabs SIO server"
) from e ) from e
self.log_mode()
return self return self
@property
def raw(self):
return self._raw
@raw.setter
def raw(self, val):
self._raw = val
self.log_mode()
def log_mode(self):
info = (f"Running client in {'raw' if self.raw else 'normal'} mode.",)
if self.raw:
info += ("raw JSON messages will be passed to callbacks",)
else:
info += ("event data objects will be passed to callbacks",)
self.logger.info(" ".join(info))
def _token_from_toml(self) -> str: def _token_from_toml(self) -> str:
try: try:
import tomllib import tomllib
@ -74,10 +56,10 @@ class Client:
raise FileNotFoundError("config.toml was not found") raise FileNotFoundError("config.toml was not found")
with open(filepath, "rb") as f: with open(filepath, "rb") as f:
conn = tomllib.load(f) conn = tomllib.load(f)
assert ( assert "token" in conn.get(
"streamlabs" in conn and "token" in conn["streamlabs"] "streamlabs"
), "expected [streamlabs][token] in config.toml" ), "token not found in config.toml"
return conn["streamlabs"]["token"] return conn["streamlabs"].get("token")
except (FileNotFoundError, tomllib.TOMLDecodeError) as e: except (FileNotFoundError, tomllib.TOMLDecodeError) as e:
self.logger.error(f"{type(e).__name__}: {e}") self.logger.error(f"{type(e).__name__}: {e}")
raise raise
@ -89,11 +71,13 @@ class Client:
if "for" in data and data["type"] in set( if "for" in data and data["type"] in set(
self.streamlabs + self.twitch + self.youtube self.streamlabs + self.twitch + self.youtube
): ):
message = data["message"][0] message = data["message"][0] if isinstance(data["message"][0], dict) else {}
self.obs.trigger( self.obs.trigger(
data["for"], data["for"],
data["type"], data["type"],
message if self.raw else as_dataclass(data["type"], message), message
if self._raw
else as_dataclass(data["type"], message),
) )
self.logger.debug(data) self.logger.debug(data)

View File

@ -1,6 +1,2 @@
class SteamlabsSIOError(Exception): class SteamlabsSIOConnectionError(Exception):
"""Base StreamlabsSIO error class"""
class SteamlabsSIOConnectionError(SteamlabsSIOError):
"""Exception raised when connection errors occur""" """Exception raised when connection errors occur"""