diff --git a/README.md b/README.md index cc61c8c..30160af 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ [![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/) -# A Python client for Streamlabs SocketIO API +# A Python client for Streamlabs Socket API ### Requirements -- A Streamlabs SocketIO API key. +- A Streamlabs Socket API key. - You can acquire this by logging into your Streamlabs.com dashboard then `Settings->Api Settings->API Tokens` ### How to install using pip @@ -54,7 +54,9 @@ if __name__ == "__main__": main() ``` -note. From the [SocketIO docs](https://python-socketio.readthedocs.io/en/latest/client.html#managing-background-tasks), `client.sio.wait()` may be used if your application has nothing to do in the main thread. +#### note + +From the [SocketIO docs](https://python-socketio.readthedocs.io/en/latest/client.html#managing-background-tasks), `client.sio.wait()` may be used if your application has nothing to do in the main thread. ### Attributes @@ -69,4 +71,4 @@ def on_twitch_event(event, msg): ### Official Documentation -- [Streamlabs SocketIO API](https://dev.streamlabs.com/docs/socket-api) +- [Streamlabs Socket API](https://dev.streamlabs.com/docs/socket-api) diff --git a/pyproject.toml b/pyproject.toml index e1d8ed6..7c7fc4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "streamlabsio" -version = "0.1.2" +version = "0.1.3" description = "Get real time Twitch/Youtube events through Streamlabs SocketIO API" authors = ["onyx-and-iris "] license = "MIT" diff --git a/streamlabsio/client.py b/streamlabsio/client.py index 8a94648..e554066 100644 --- a/streamlabsio/client.py +++ b/streamlabsio/client.py @@ -13,7 +13,7 @@ from .models import as_dataclass class Client: - logger = logging.getLogger("socketio.socketio") + logger = logging.getLogger("socketio.client") def __init__(self, token=None): self.token = token or self._token_from_toml() @@ -22,6 +22,9 @@ class Client: self.sio.on("event", self.event_handler) self.sio.on("disconnect", self.disconnect_handler) self.obs = Observable() + self.streamlabs = ("donation",) + self.twitch = ("follow", "subscription", "host", "bits", "raids") + self.youtube = ("follow", "subscription", "superchat") def __enter__(self): self.sio.connect(f"https://sockets.streamlabs.com?token={self.token}") @@ -35,17 +38,20 @@ class Client: return conn["streamlabs"].get("token") def connect_handler(self): - self.logger.info("Connected to Twitch Socketio") + self.logger.info("Connected to Streamlabs Socket API") def event_handler(self, data): - self.obs.trigger( - data.get("for"), - data["type"], - as_dataclass(data["type"], *data["message"]), - ) + if "for" in data and data["type"] in set( + self.streamlabs + self.twitch + self.youtube + ): + self.obs.trigger( + data["for"], + data["type"], + as_dataclass(data["type"], *data["message"]), + ) def disconnect_handler(self): - self.logger.info("Disconnected from Twitch Socketio") + self.logger.info("Disconnected from Streamlabs Socket API") def __exit__(self, exc_type, exc_val, exc_tb): self.sio.disconnect()