mirror of
				https://github.com/onyx-and-iris/streamlabs-socketio-py
				synced 2025-10-30 17:31:47 +00:00 
			
		
		
		
	Compare commits
	
		
			5 Commits
		
	
	
		
			e92c3b2e6f
			...
			822bdfb60d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 822bdfb60d | |||
| 6e13e71a09 | |||
| 7bea4453fa | |||
| 7d7704dd28 | |||
| d9e8c5391a | 
| @ -1,5 +1,6 @@ | ||||
| [](https://badge.fury.io/py/streamlabsio) | ||||
| [](https://github.com/onyx-and-iris/streamlabs-socketio-py/blob/dev/LICENSE) | ||||
| [](https://python-poetry.org/) | ||||
| [](https://github.com/psf/black) | ||||
| [](https://pycqa.github.io/isort/) | ||||
| 
 | ||||
| @ -70,6 +71,10 @@ The following keyword arguments may be passed: | ||||
| -   `token`: str   Streamlabs SocketIO api token. | ||||
| -   `raw`: boolean=False    Receive raw data messages as json objects. | ||||
| 
 | ||||
| The following attribute is available: | ||||
| 
 | ||||
| -   `raw`: boolean Toggle raw mode at runtime. | ||||
| 
 | ||||
| ### Attributes | ||||
| 
 | ||||
| For event data you may inspect the available attributes using `attrs()`. | ||||
| @ -83,6 +88,7 @@ def on_twitch_event(event, data): | ||||
| 
 | ||||
| ### Errors | ||||
| 
 | ||||
| -   `SteamlabsSIOError`: Base StreamlabsSIO error class | ||||
| -   `SteamlabsSIOConnectionError`: Exception raised when connection errors occur | ||||
| 
 | ||||
| ### Logging | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| [tool.poetry] | ||||
| name = "streamlabsio" | ||||
| version = "1.0.2" | ||||
| version = "1.1.1" | ||||
| description = "Get real time Twitch/Youtube events through Streamlabs SocketIO API" | ||||
| authors = ["onyx-and-iris <code@onyxandiris.online>"] | ||||
| license = "MIT" | ||||
|  | ||||
| @ -1,7 +1,8 @@ | ||||
| import subprocess | ||||
| import sys | ||||
| from pathlib import Path | ||||
| 
 | ||||
| 
 | ||||
| def ex_debug(): | ||||
|     path = Path.cwd() / "examples" / "debug" / "." | ||||
|     subprocess.run(["py", str(path)]) | ||||
|     scriptpath = Path.cwd() / "examples" / "debug" / "." | ||||
|     subprocess.run([sys.executable, str(scriptpath)]) | ||||
|  | ||||
| @ -33,8 +33,26 @@ class Client: | ||||
|             raise SteamlabsSIOConnectionError( | ||||
|                 "no connection could be established to the Streamlabs SIO server" | ||||
|             ) from e | ||||
|         self.log_mode() | ||||
|         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: | ||||
|         try: | ||||
|             import tomllib | ||||
| @ -56,10 +74,10 @@ class Client: | ||||
|                 raise FileNotFoundError("config.toml was not found") | ||||
|             with open(filepath, "rb") as f: | ||||
|                 conn = tomllib.load(f) | ||||
|                 assert "token" in conn.get( | ||||
|                     "streamlabs" | ||||
|                 ), "token not found in config.toml" | ||||
|             return conn["streamlabs"].get("token") | ||||
|                 assert ( | ||||
|                     "streamlabs" in conn and "token" in conn["streamlabs"] | ||||
|                 ), "expected [streamlabs][token] in config.toml" | ||||
|             return conn["streamlabs"]["token"] | ||||
|         except (FileNotFoundError, tomllib.TOMLDecodeError) as e: | ||||
|             self.logger.error(f"{type(e).__name__}: {e}") | ||||
|             raise | ||||
| @ -71,13 +89,11 @@ class Client: | ||||
|         if "for" in data and data["type"] in set( | ||||
|             self.streamlabs + self.twitch + self.youtube | ||||
|         ): | ||||
|             message = data["message"][0] if isinstance(data["message"][0], dict) else {} | ||||
|             message = data["message"][0] | ||||
|             self.obs.trigger( | ||||
|                 data["for"], | ||||
|                 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) | ||||
| 
 | ||||
|  | ||||
| @ -1,2 +1,6 @@ | ||||
| class SteamlabsSIOConnectionError(Exception): | ||||
| class SteamlabsSIOError(Exception): | ||||
|     """Base StreamlabsSIO error class""" | ||||
| 
 | ||||
| 
 | ||||
| class SteamlabsSIOConnectionError(SteamlabsSIOError): | ||||
|     """Exception raised when connection errors occur""" | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user