mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2026-04-18 06:53:38 +00:00
dynamically load commands from obsws_cli.commands
no changes to files other than imports patch bump
This commit is contained in:
172
obsws_cli/commands/record.py
Normal file
172
obsws_cli/commands/record.py
Normal file
@@ -0,0 +1,172 @@
|
||||
"""module for controlling OBS recording functionality."""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Annotated, Optional
|
||||
|
||||
import typer
|
||||
|
||||
from obsws_cli import console
|
||||
from obsws_cli.alias import SubTyperAliasGroup
|
||||
|
||||
app = typer.Typer(cls=SubTyperAliasGroup)
|
||||
|
||||
|
||||
@app.callback()
|
||||
def main():
|
||||
"""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('start | s')
|
||||
def start(ctx: typer.Context):
|
||||
"""Start recording."""
|
||||
active, paused = _get_recording_status(ctx)
|
||||
if active:
|
||||
err_msg = 'Recording is already in progress, cannot start.'
|
||||
if paused:
|
||||
err_msg += ' Try resuming it.'
|
||||
|
||||
console.err.print(err_msg)
|
||||
raise typer.Exit(1)
|
||||
|
||||
ctx.obj['obsws'].start_record()
|
||||
console.out.print('Recording started successfully.')
|
||||
|
||||
|
||||
@app.command('stop | st')
|
||||
def stop(ctx: typer.Context):
|
||||
"""Stop recording."""
|
||||
active, _ = _get_recording_status(ctx)
|
||||
if not active:
|
||||
console.err.print('Recording is not in progress, cannot stop.')
|
||||
raise typer.Exit(1)
|
||||
|
||||
resp = ctx.obj['obsws'].stop_record()
|
||||
console.out.print(
|
||||
f'Recording stopped successfully. Saved to: {console.highlight(ctx, resp.output_path)}'
|
||||
)
|
||||
|
||||
|
||||
@app.command('toggle | tg')
|
||||
def toggle(ctx: typer.Context):
|
||||
"""Toggle recording."""
|
||||
resp = ctx.obj['obsws'].toggle_record()
|
||||
if resp.output_active:
|
||||
console.out.print('Recording started successfully.')
|
||||
else:
|
||||
console.out.print('Recording stopped successfully.')
|
||||
|
||||
|
||||
@app.command('status | ss')
|
||||
def status(ctx: typer.Context):
|
||||
"""Get recording status."""
|
||||
active, paused = _get_recording_status(ctx)
|
||||
if active:
|
||||
if paused:
|
||||
console.out.print('Recording is in progress and paused.')
|
||||
else:
|
||||
console.out.print('Recording is in progress.')
|
||||
else:
|
||||
console.out.print('Recording is not in progress.')
|
||||
|
||||
|
||||
@app.command('resume | r')
|
||||
def resume(ctx: typer.Context):
|
||||
"""Resume recording."""
|
||||
active, paused = _get_recording_status(ctx)
|
||||
if not active:
|
||||
console.err.print('Recording is not in progress, cannot resume.')
|
||||
raise typer.Exit(1)
|
||||
if not paused:
|
||||
console.err.print('Recording is in progress but not paused, cannot resume.')
|
||||
raise typer.Exit(1)
|
||||
|
||||
ctx.obj['obsws'].resume_record()
|
||||
console.out.print('Recording resumed successfully.')
|
||||
|
||||
|
||||
@app.command('pause | p')
|
||||
def pause(ctx: typer.Context):
|
||||
"""Pause recording."""
|
||||
active, paused = _get_recording_status(ctx)
|
||||
if not active:
|
||||
console.err.print('Recording is not in progress, cannot pause.')
|
||||
raise typer.Exit(1)
|
||||
if paused:
|
||||
console.err.print('Recording is in progress but already paused, cannot pause.')
|
||||
raise typer.Exit(1)
|
||||
|
||||
ctx.obj['obsws'].pause_record()
|
||||
console.out.print('Recording paused successfully.')
|
||||
|
||||
|
||||
@app.command('directory | d')
|
||||
def directory(
|
||||
ctx: typer.Context,
|
||||
record_directory: Annotated[
|
||||
Optional[Path],
|
||||
# Since the CLI and OBS may be running on different platforms,
|
||||
# we won't validate the path here.
|
||||
typer.Argument(
|
||||
file_okay=False,
|
||||
dir_okay=True,
|
||||
help='Directory to set for recording.',
|
||||
),
|
||||
] = None,
|
||||
):
|
||||
"""Get or set the recording directory."""
|
||||
if record_directory is not None:
|
||||
ctx.obj['obsws'].set_record_directory(str(record_directory))
|
||||
console.out.print(
|
||||
f'Recording directory updated to: {console.highlight(ctx, record_directory)}'
|
||||
)
|
||||
else:
|
||||
resp = ctx.obj['obsws'].get_record_directory()
|
||||
console.out.print(
|
||||
f'Recording directory: {console.highlight(ctx, resp.record_directory)}'
|
||||
)
|
||||
|
||||
|
||||
@app.command('split | sp')
|
||||
def split(ctx: typer.Context):
|
||||
"""Split the current recording."""
|
||||
active, paused = _get_recording_status(ctx)
|
||||
if not active:
|
||||
console.err.print('Recording is not in progress, cannot split.')
|
||||
raise typer.Exit(1)
|
||||
if paused:
|
||||
console.err.print('Recording is paused, cannot split.')
|
||||
raise typer.Exit(1)
|
||||
|
||||
ctx.obj['obsws'].split_record_file()
|
||||
console.out.print('Recording split successfully.')
|
||||
|
||||
|
||||
@app.command('chapter | ch')
|
||||
def chapter(
|
||||
ctx: typer.Context,
|
||||
chapter_name: Annotated[
|
||||
Optional[str],
|
||||
typer.Argument(
|
||||
help='Name of the chapter to create.',
|
||||
),
|
||||
] = None,
|
||||
):
|
||||
"""Create a chapter in the current recording."""
|
||||
active, paused = _get_recording_status(ctx)
|
||||
if not active:
|
||||
console.err.print('Recording is not in progress, cannot create chapter.')
|
||||
raise typer.Exit(1)
|
||||
if paused:
|
||||
console.err.print('Recording is paused, cannot create chapter.')
|
||||
raise typer.Exit(1)
|
||||
|
||||
ctx.obj['obsws'].create_record_chapter(chapter_name)
|
||||
console.out.print(
|
||||
f'Chapter {console.highlight(ctx, chapter_name or "unnamed")} created successfully.'
|
||||
)
|
||||
Reference in New Issue
Block a user