mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-05-16 22:40:23 +01:00
check recording status to clean up stack traces
toggle command now invokes stop/start patch bump
This commit is contained in:
parent
a9e8ef8f6d
commit
edd3753d4d
@ -1,4 +1,4 @@
|
|||||||
# SPDX-FileCopyrightText: 2025-present onyx-and-iris <code@onyxandiris.online>
|
# SPDX-FileCopyrightText: 2025-present onyx-and-iris <code@onyxandiris.online>
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
__version__ = "0.6.0"
|
__version__ = "0.6.1"
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
"""module for controlling OBS recording functionality."""
|
"""module for controlling OBS recording functionality."""
|
||||||
|
|
||||||
import obsws_python as obsws
|
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
from .errors import ObswsCliError
|
from .alias import AliasGroup
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer(cls=AliasGroup)
|
||||||
|
|
||||||
|
|
||||||
@app.callback()
|
@app.callback()
|
||||||
@ -13,36 +12,38 @@ def main():
|
|||||||
"""Control OBS recording functionality."""
|
"""Control OBS recording functionality."""
|
||||||
|
|
||||||
|
|
||||||
|
def _get_recording_status(ctx: typer.Context) -> tuple:
|
||||||
|
"""Get recording status."""
|
||||||
|
resp = ctx.obj['obsws'].get_record_status()
|
||||||
|
return resp.output_active, resp.output_paused
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def start(ctx: typer.Context):
|
def start(ctx: typer.Context):
|
||||||
"""Start recording."""
|
"""Start recording."""
|
||||||
try:
|
active, paused = _get_recording_status(ctx)
|
||||||
ctx.obj['obsws'].start_record()
|
if active:
|
||||||
typer.echo('Recording started successfully.')
|
err_msg = 'Recording is already in progress, cannot start.'
|
||||||
except obsws.error.OBSSDKRequestError as e:
|
if paused:
|
||||||
if e.code == 500:
|
err_msg += ' Try resuming it.'
|
||||||
raise ObswsCliError(
|
|
||||||
'Recording is already in progress, cannot start.'
|
typer.echo(err_msg)
|
||||||
) from e
|
raise typer.Exit(1)
|
||||||
raise
|
|
||||||
|
ctx.obj['obsws'].start_record()
|
||||||
|
typer.echo('Recording started successfully.')
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def stop(ctx: typer.Context):
|
def stop(ctx: typer.Context):
|
||||||
"""Stop recording."""
|
"""Stop recording."""
|
||||||
try:
|
active, _ = _get_recording_status(ctx)
|
||||||
ctx.obj['obsws'].stop_record()
|
if not active:
|
||||||
typer.echo('Recording stopped successfully.')
|
typer.echo('Recording is not in progress, cannot stop.')
|
||||||
except obsws.error.OBSSDKRequestError as e:
|
raise typer.Exit(1)
|
||||||
if e.code == 501:
|
|
||||||
raise ObswsCliError('Recording is not in progress, cannot stop.') from e
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
ctx.obj['obsws'].stop_record()
|
||||||
def _get_recording_status(ctx: typer.Context) -> tuple:
|
typer.echo('Recording stopped successfully.')
|
||||||
"""Get recording status."""
|
|
||||||
resp = ctx.obj['obsws'].get_record_status()
|
|
||||||
return resp.output_active, resp.output_paused
|
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
@ -63,17 +64,9 @@ def toggle(ctx: typer.Context):
|
|||||||
"""Toggle recording."""
|
"""Toggle recording."""
|
||||||
active, _ = _get_recording_status(ctx)
|
active, _ = _get_recording_status(ctx)
|
||||||
if active:
|
if active:
|
||||||
try:
|
ctx.invoke(stop, ctx=ctx)
|
||||||
ctx.obj['obsws'].stop_record()
|
|
||||||
typer.echo('Recording stopped successfully.')
|
|
||||||
except obsws.error.OBSSDKRequestError as e:
|
|
||||||
raise ObswsCliError(str(e)) from e
|
|
||||||
else:
|
else:
|
||||||
try:
|
ctx.invoke(start, ctx=ctx)
|
||||||
ctx.obj['obsws'].start_record()
|
|
||||||
typer.echo('Recording started successfully.')
|
|
||||||
except obsws.error.OBSSDKRequestError as e:
|
|
||||||
raise ObswsCliError(str(e)) from e
|
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
@ -81,15 +74,14 @@ def resume(ctx: typer.Context):
|
|||||||
"""Resume recording."""
|
"""Resume recording."""
|
||||||
active, paused = _get_recording_status(ctx)
|
active, paused = _get_recording_status(ctx)
|
||||||
if not active:
|
if not active:
|
||||||
raise ObswsCliError('Recording is not in progress, cannot resume.')
|
typer.echo('Recording is not in progress, cannot resume.')
|
||||||
|
raise typer.Exit(1)
|
||||||
if not paused:
|
if not paused:
|
||||||
raise ObswsCliError('Recording is in progress but not paused, cannot resume.')
|
typer.echo('Recording is in progress but not paused, cannot resume.')
|
||||||
|
raise typer.Exit(1)
|
||||||
|
|
||||||
try:
|
ctx.obj['obsws'].resume_record()
|
||||||
ctx.obj['obsws'].resume_record()
|
typer.echo('Recording resumed successfully.')
|
||||||
typer.echo('Recording resumed successfully.')
|
|
||||||
except obsws.error.OBSSDKRequestError as e:
|
|
||||||
raise ObswsCliError(str(e)) from e
|
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
@ -97,14 +89,11 @@ def pause(ctx: typer.Context):
|
|||||||
"""Pause recording."""
|
"""Pause recording."""
|
||||||
active, paused = _get_recording_status(ctx)
|
active, paused = _get_recording_status(ctx)
|
||||||
if not active:
|
if not active:
|
||||||
raise ObswsCliError('Recording is not in progress, cannot pause.')
|
typer.echo('Recording is not in progress, cannot pause.')
|
||||||
|
raise typer.Exit(1)
|
||||||
if paused:
|
if paused:
|
||||||
raise ObswsCliError(
|
typer.echo('Recording is in progress but already paused, cannot pause.')
|
||||||
'Recording is in progress but already paused, cannot pause.'
|
raise typer.Exit(1)
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
ctx.obj['obsws'].pause_record()
|
||||||
ctx.obj['obsws'].pause_record()
|
typer.echo('Recording paused successfully.')
|
||||||
typer.echo('Recording paused successfully.')
|
|
||||||
except obsws.error.OBSSDKRequestError as e:
|
|
||||||
raise ObswsCliError(str(e)) from e
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user