mirror of
				https://github.com/onyx-and-iris/obsws-cli.git
				synced 2025-10-31 13:41:50 +00:00 
			
		
		
		
	check streaming status to clean up stack traces
toggle command now invokes stop/start added toggle alias tg patch bump
This commit is contained in:
		
							parent
							
								
									edd3753d4d
								
							
						
					
					
						commit
						2175fb8788
					
				| @ -1,4 +1,4 @@ | ||||
| # SPDX-FileCopyrightText: 2025-present onyx-and-iris <code@onyxandiris.online> | ||||
| # | ||||
| # SPDX-License-Identifier: MIT | ||||
| __version__ = "0.6.1" | ||||
| __version__ = "0.6.2" | ||||
|  | ||||
| @ -1,11 +1,10 @@ | ||||
| """module for controlling OBS stream functionality.""" | ||||
| 
 | ||||
| import obsws_python as obsws | ||||
| import typer | ||||
| 
 | ||||
| from .errors import ObswsCliError | ||||
| from .alias import AliasGroup | ||||
| 
 | ||||
| app = typer.Typer() | ||||
| app = typer.Typer(cls=AliasGroup) | ||||
| 
 | ||||
| 
 | ||||
| @app.callback() | ||||
| @ -13,36 +12,34 @@ def main(): | ||||
|     """Control OBS stream functionality.""" | ||||
| 
 | ||||
| 
 | ||||
| def _get_streaming_status(ctx: typer.Context) -> tuple: | ||||
|     """Get streaming status.""" | ||||
|     resp = ctx.obj['obsws'].get_stream_status() | ||||
|     return resp.output_active, resp.output_duration | ||||
| 
 | ||||
| 
 | ||||
| @app.command() | ||||
| def start(ctx: typer.Context): | ||||
|     """Start streaming.""" | ||||
|     try: | ||||
|         ctx.obj['obsws'].start_stream() | ||||
|         typer.echo('Streaming started successfully.') | ||||
|     except obsws.error.OBSSDKRequestError as e: | ||||
|         if e.code == 500: | ||||
|             raise ObswsCliError( | ||||
|                 'Streaming is already in progress, cannot start.' | ||||
|             ) from e | ||||
|         raise | ||||
|     active, _ = _get_streaming_status(ctx) | ||||
|     if active: | ||||
|         typer.echo('Streaming is already in progress, cannot start.') | ||||
|         raise typer.Exit(code=1) | ||||
| 
 | ||||
|     ctx.obj['obsws'].start_stream() | ||||
|     typer.echo('Streaming started successfully.') | ||||
| 
 | ||||
| 
 | ||||
| @app.command() | ||||
| def stop(ctx: typer.Context): | ||||
|     """Stop streaming.""" | ||||
|     try: | ||||
|         ctx.obj['obsws'].stop_stream() | ||||
|         typer.echo('Streaming stopped successfully.') | ||||
|     except obsws.error.OBSSDKRequestError as e: | ||||
|         if e.code == 501: | ||||
|             raise ObswsCliError('Streaming is not in progress, cannot stop.') from e | ||||
|         raise | ||||
|     active, _ = _get_streaming_status(ctx) | ||||
|     if not active: | ||||
|         typer.echo('Streaming is not in progress, cannot stop.') | ||||
|         raise typer.Exit(code=1) | ||||
| 
 | ||||
| 
 | ||||
| def _get_streaming_status(ctx: typer.Context) -> tuple: | ||||
|     """Get streaming status.""" | ||||
|     resp = ctx.obj['obsws'].get_stream_status() | ||||
|     return resp.output_active, resp.output_duration | ||||
|     ctx.obj['obsws'].stop_stream() | ||||
|     typer.echo('Streaming stopped successfully.') | ||||
| 
 | ||||
| 
 | ||||
| @app.command() | ||||
| @ -74,14 +71,6 @@ def toggle(ctx: typer.Context): | ||||
|     """Toggle streaming.""" | ||||
|     active, _ = _get_streaming_status(ctx) | ||||
|     if active: | ||||
|         try: | ||||
|             ctx.obj['obsws'].stop_stream() | ||||
|             typer.echo('Streaming stopped successfully.') | ||||
|         except obsws.error.OBSSDKRequestError as e: | ||||
|             raise ObswsCliError(str(e)) from e | ||||
|         ctx.invoke(stop, ctx=ctx) | ||||
|     else: | ||||
|         try: | ||||
|             ctx.obj['obsws'].start_stream() | ||||
|             typer.echo('Streaming started successfully.') | ||||
|         except obsws.error.OBSSDKRequestError as e: | ||||
|             raise ObswsCliError(str(e)) from e | ||||
|         ctx.invoke(start, ctx=ctx) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user