mirror of
https://github.com/onyx-and-iris/slobs-cli.git
synced 2025-06-27 15:20:24 +01:00
implement stream command group
minor bump
This commit is contained in:
parent
f35a1594c6
commit
ad6c0bb042
@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "slobs-cli"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
description = "A command line application for Streamlabs Desktop"
|
||||
authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }]
|
||||
dependencies = ["pyslobs>=2.0.4", "asyncclick>=8.1.8"]
|
||||
|
105
src/slobs_cli/stream.py
Normal file
105
src/slobs_cli/stream.py
Normal file
@ -0,0 +1,105 @@
|
||||
import asyncclick as click
|
||||
from anyio import create_task_group
|
||||
from pyslobs import StreamingService
|
||||
|
||||
from .cli import cli
|
||||
|
||||
|
||||
@cli.group()
|
||||
def stream():
|
||||
"""Stream management commands."""
|
||||
|
||||
|
||||
@stream.command()
|
||||
@click.pass_context
|
||||
async def start(ctx: click.Context):
|
||||
"""Start the stream."""
|
||||
|
||||
conn = ctx.obj["connection"]
|
||||
ss = StreamingService(conn)
|
||||
|
||||
async def _run(conn):
|
||||
current_state = await ss.get_model()
|
||||
active = current_state.streaming_status != "offline"
|
||||
|
||||
if active:
|
||||
conn.close()
|
||||
raise click.Abort(click.style("Stream is already active.", fg="red"))
|
||||
|
||||
await ss.toggle_streaming()
|
||||
click.echo("Stream started.")
|
||||
conn.close()
|
||||
|
||||
async with create_task_group() as tg:
|
||||
tg.start_soon(conn.background_processing)
|
||||
tg.start_soon(_run, conn)
|
||||
|
||||
|
||||
@stream.command()
|
||||
@click.pass_context
|
||||
async def stop(ctx: click.Context):
|
||||
"""Stop the stream."""
|
||||
|
||||
conn = ctx.obj["connection"]
|
||||
ss = StreamingService(conn)
|
||||
|
||||
async def _run(conn):
|
||||
current_state = await ss.get_model()
|
||||
active = current_state.streaming_status != "offline"
|
||||
|
||||
if not active:
|
||||
conn.close()
|
||||
raise click.Abort(click.style("Stream is already inactive.", fg="red"))
|
||||
|
||||
await ss.toggle_streaming()
|
||||
click.echo("Stream stopped.")
|
||||
conn.close()
|
||||
|
||||
async with create_task_group() as tg:
|
||||
tg.start_soon(conn.background_processing)
|
||||
tg.start_soon(_run, conn)
|
||||
|
||||
|
||||
@stream.command()
|
||||
@click.pass_context
|
||||
async def status(ctx: click.Context):
|
||||
"""Get the current stream status."""
|
||||
|
||||
conn = ctx.obj["connection"]
|
||||
ss = StreamingService(conn)
|
||||
|
||||
async def _run(conn):
|
||||
current_state = await ss.get_model()
|
||||
status = current_state.streaming_status
|
||||
click.echo(f"Current stream status: {status}")
|
||||
conn.close()
|
||||
|
||||
async with create_task_group() as tg:
|
||||
tg.start_soon(conn.background_processing)
|
||||
tg.start_soon(_run, conn)
|
||||
|
||||
|
||||
@stream.command()
|
||||
@click.pass_context
|
||||
async def toggle(ctx: click.Context):
|
||||
"""Toggle the stream status."""
|
||||
|
||||
conn = ctx.obj["connection"]
|
||||
ss = StreamingService(conn)
|
||||
|
||||
async def _run(conn):
|
||||
current_state = await ss.get_model()
|
||||
active = current_state.streaming_status != "offline"
|
||||
|
||||
if active:
|
||||
await ss.toggle_streaming()
|
||||
click.echo("Stream stopped.")
|
||||
else:
|
||||
await ss.toggle_streaming()
|
||||
click.echo("Stream started.")
|
||||
|
||||
conn.close()
|
||||
|
||||
async with create_task_group() as tg:
|
||||
tg.start_soon(conn.background_processing)
|
||||
tg.start_soon(_run, conn)
|
Loading…
x
Reference in New Issue
Block a user