Compare commits

..

No commits in common. "5189ee1d5b5053599793dd2d4574052b846e7836" and "e72d1d2eb89515605c6172bc6c3d76954ed3ca86" have entirely different histories.

10 changed files with 46 additions and 302 deletions

View File

@ -5,12 +5,6 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
# [0.12.0] - 2025-05-23
### Added
- filter commands, see [Filter](https://github.com/onyx-and-iris/obsws-cli?tab=readme-ov-file#filter)
# [0.11.0] - 2025-05-22
### Added

View File

@ -205,10 +205,7 @@ obsws-cli scenecollection create test-collection
#### Group
- list: List groups in a scene.
*optional*
- args: <scene_name>
- defaults to current scene
```console
obsws-cli group list START
@ -489,42 +486,6 @@ obsws-cli hotkey trigger-sequence OBS_KEY_F1 --ctrl
obsws-cli hotkey trigger-sequence OBS_KEY_F1 --shift --ctrl
```
#### Filter
- list: List filters for a source.
- args: <source_name>
```console
obsws-cli filter list "Mic/Aux"
```
- enable: Enable a filter for a source.
- args: <source_name> <filter_name>
```console
obsws-cli filter enable "Mic/Aux" "Test Compression Filter"
```
- disable: Disable a filter for a source.
- args: <source_name> <filter_name>
```console
obsws-cli filter disable "Mic/Aux" "Test Compression Filter"
```
- toggle: Toggle a filter for a source.
- args: <source_name> <filter_name>
```console
obsws-cli filter toggle "Mic/Aux" "Test Compression Filter"
```
- status: Get the status of a filter for a source.
- args: <source_name> <filter_name>
```console
obsws-cli filter status "Mic/Aux" "Test Compression Filter"
```
## License

View File

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025-present onyx-and-iris <code@onyxandiris.online>
#
# SPDX-License-Identifier: MIT
__version__ = "0.12.4"
__version__ = "0.11.0"

View File

@ -6,7 +6,6 @@ import obsws_python as obsws
import typer
from . import (
filter,
group,
hotkey,
input,
@ -25,7 +24,6 @@ from .alias import AliasGroup
app = typer.Typer(cls=AliasGroup)
for module in (
filter,
group,
hotkey,
input,

View File

@ -1,122 +0,0 @@
"""module containing commands for manipulating filters in scenes."""
import typer
from rich.console import Console
from rich.table import Table
from . import util
from .alias import AliasGroup
app = typer.Typer(cls=AliasGroup)
out_console = Console()
err_console = Console(stderr=True)
@app.callback()
def main():
"""Control filters in OBS scenes."""
@app.command('list | ls')
def list(ctx: typer.Context, source_name: str):
"""List filters for a source."""
resp = ctx.obj.get_source_filter_list(source_name)
if not resp.filters:
out_console.print(f'No filters found for source {source_name}')
return
table = Table(title=f'Filters for Source: {source_name}')
for column in ('Name', 'Kind', 'Enabled', 'Settings'):
table.add_column(column, justify='center', style='cyan')
for filter in resp.filters:
table.add_row(
filter['filterName'],
util.snakecase_to_titlecase(filter['filterKind']),
':heavy_check_mark:' if filter['filterEnabled'] else ':x:',
'\n'.join(
[
f'{util.snakecase_to_titlecase(k):<20} {v:>10}'
for k, v in filter['filterSettings'].items()
]
),
)
out_console.print(table)
def _get_filter_enabled(ctx: typer.Context, source_name: str, filter_name: str):
"""Get the status of a filter for a source."""
resp = ctx.obj.get_source_filter(source_name, filter_name)
return resp.filter_enabled
@app.command('enable | on')
def enable(
ctx: typer.Context,
source_name: str = typer.Argument(..., help='The source to enable the filter for'),
filter_name: str = typer.Argument(..., help='The name of the filter to enable'),
):
"""Enable a filter for a source."""
if _get_filter_enabled(ctx, source_name, filter_name):
err_console.print(
f'Filter {filter_name} is already enabled for source {source_name}'
)
raise typer.Exit(1)
ctx.obj.set_source_filter_enabled(source_name, filter_name, enabled=True)
out_console.print(f'Enabled filter {filter_name} for source {source_name}')
@app.command('disable | off')
def disable(
ctx: typer.Context,
source_name: str = typer.Argument(..., help='The source to disable the filter for'),
filter_name: str = typer.Argument(..., help='The name of the filter to disable'),
):
"""Disable a filter for a source."""
if not _get_filter_enabled(ctx, source_name, filter_name):
err_console.print(
f'Filter {filter_name} is already disabled for source {source_name}'
)
raise typer.Exit(1)
ctx.obj.set_source_filter_enabled(source_name, filter_name, enabled=False)
out_console.print(f'Disabled filter {filter_name} for source {source_name}')
@app.command('toggle | tg')
def toggle(
ctx: typer.Context,
source_name: str = typer.Argument(..., help='The source to toggle the filter for'),
filter_name: str = typer.Argument(..., help='The name of the filter to toggle'),
):
"""Toggle a filter for a source."""
is_enabled = _get_filter_enabled(ctx, source_name, filter_name)
new_state = not is_enabled
ctx.obj.set_source_filter_enabled(source_name, filter_name, enabled=new_state)
if new_state:
out_console.print(f'Enabled filter {filter_name} for source {source_name}')
else:
out_console.print(f'Disabled filter {filter_name} for source {source_name}')
@app.command('status | ss')
def status(
ctx: typer.Context,
source_name: str = typer.Argument(
..., help='The source to get the filter status for'
),
filter_name: str = typer.Argument(
..., help='The name of the filter to get the status for'
),
):
"""Get the status of a filter for a source."""
is_enabled = _get_filter_enabled(ctx, source_name, filter_name)
if is_enabled:
out_console.print(f'Filter {filter_name} is enabled for source {source_name}')
else:
out_console.print(f'Filter {filter_name} is disabled for source {source_name}')

View File

@ -1,16 +1,12 @@
"""module containing commands for manipulating groups in scenes."""
import typer
from rich.console import Console
from rich.table import Table
from . import validate
from .alias import AliasGroup
from .protocols import DataclassProtocol
app = typer.Typer(cls=AliasGroup)
out_console = Console()
err_console = Console(stderr=True)
@app.callback()
@ -19,46 +15,17 @@ def main():
@app.command('list | ls')
def list(
ctx: typer.Context,
scene_name: str = typer.Argument(
None, help='Scene name (optional, defaults to current scene)'
),
):
def list(ctx: typer.Context, scene_name: str):
"""List groups in a scene."""
if not scene_name:
scene_name = ctx.obj.get_current_program_scene().scene_name
if not validate.scene_in_scenes(ctx, scene_name):
err_console.print(f"Scene '{scene_name}' not found.")
typer.echo(f"Scene '{scene_name}' not found.", err=True)
raise typer.Exit(1)
resp = ctx.obj.get_scene_item_list(scene_name)
groups = [
(item.get('sceneItemId'), item.get('sourceName'), item.get('sceneItemEnabled'))
for item in resp.scene_items
if item.get('isGroup')
]
if not groups:
err_console.print(f"No groups found in scene '{scene_name}'.")
raise typer.Exit(1)
table = Table(title=f'Groups in Scene: {scene_name}')
for column in ('ID', 'Name', 'Enabled'):
table.add_column(
column, justify='left' if column == 'Name' else 'center', style='cyan'
)
for item_id, group_name, is_enabled in groups:
table.add_row(
str(item_id),
group_name,
':heavy_check_mark:' if is_enabled else ':x:',
)
out_console.print(table)
groups = (
item.get('sourceName') for item in resp.scene_items if item.get('isGroup')
)
typer.echo('\n'.join(groups))
def _get_group(group_name: str, resp: DataclassProtocol) -> dict | None:
@ -78,12 +45,12 @@ def _get_group(group_name: str, resp: DataclassProtocol) -> dict | None:
def show(ctx: typer.Context, scene_name: str, group_name: str):
"""Show a group in a scene."""
if not validate.scene_in_scenes(ctx, scene_name):
err_console.print(f"Scene '{scene_name}' not found.")
typer.echo(f"Scene '{scene_name}' not found.", err=True)
raise typer.Exit(1)
resp = ctx.obj.get_scene_item_list(scene_name)
if (group := _get_group(group_name, resp)) is None:
err_console.print(f"Group '{group_name}' not found in scene {scene_name}.")
typer.echo(f"Group '{group_name}' not found in scene {scene_name}.", err=True)
raise typer.Exit(1)
ctx.obj.set_scene_item_enabled(
@ -92,19 +59,19 @@ def show(ctx: typer.Context, scene_name: str, group_name: str):
enabled=True,
)
out_console.print(f"Group '{group_name}' is now visible.")
typer.echo(f"Group '{group_name}' is now visible.")
@app.command('hide | h')
def hide(ctx: typer.Context, scene_name: str, group_name: str):
"""Hide a group in a scene."""
if not validate.scene_in_scenes(ctx, scene_name):
err_console.print(f"Scene '{scene_name}' not found.")
typer.echo(f"Scene '{scene_name}' not found.", err=True)
raise typer.Exit(1)
resp = ctx.obj.get_scene_item_list(scene_name)
if (group := _get_group(group_name, resp)) is None:
err_console.print(f"Group '{group_name}' not found in scene {scene_name}.")
typer.echo(f"Group '{group_name}' not found in scene {scene_name}.", err=True)
raise typer.Exit(1)
ctx.obj.set_scene_item_enabled(
@ -113,19 +80,19 @@ def hide(ctx: typer.Context, scene_name: str, group_name: str):
enabled=False,
)
out_console.print(f"Group '{group_name}' is now hidden.")
typer.echo(f"Group '{group_name}' is now hidden.")
@app.command('toggle | tg')
def toggle(ctx: typer.Context, scene_name: str, group_name: str):
"""Toggle a group in a scene."""
if not validate.scene_in_scenes(ctx, scene_name):
err_console.print(f"Scene '{scene_name}' not found.")
typer.echo(f"Scene '{scene_name}' not found.", err=True)
raise typer.Exit(1)
resp = ctx.obj.get_scene_item_list(scene_name)
if (group := _get_group(group_name, resp)) is None:
err_console.print(f"Group '{group_name}' not found in scene {scene_name}.")
typer.echo(f"Group '{group_name}' not found in scene {scene_name}.", err=True)
raise typer.Exit(1)
new_state = not group.get('sceneItemEnabled')
@ -136,21 +103,21 @@ def toggle(ctx: typer.Context, scene_name: str, group_name: str):
)
if new_state:
out_console.print(f"Group '{group_name}' is now visible.")
typer.echo(f"Group '{group_name}' is now visible.")
else:
out_console.print(f"Group '{group_name}' is now hidden.")
typer.echo(f"Group '{group_name}' is now hidden.")
@app.command('status | ss')
def status(ctx: typer.Context, scene_name: str, group_name: str):
"""Get the status of a group in a scene."""
if not validate.scene_in_scenes(ctx, scene_name):
err_console.print(f"Scene '{scene_name}' not found.")
typer.echo(f"Scene '{scene_name}' not found.", err=True)
raise typer.Exit(1)
resp = ctx.obj.get_scene_item_list(scene_name)
if (group := _get_group(group_name, resp)) is None:
err_console.print(f"Group '{group_name}' not found in scene {scene_name}.")
typer.echo(f"Group '{group_name}' not found in scene {scene_name}.", err=True)
raise typer.Exit(1)
enabled = ctx.obj.get_scene_item_enabled(
@ -159,6 +126,6 @@ def status(ctx: typer.Context, scene_name: str, group_name: str):
)
if enabled.scene_item_enabled:
out_console.print(f"Group '{group_name}' is now visible.")
typer.echo(f"Group '{group_name}' is now visible.")
else:
out_console.print(f"Group '{group_name}' is now hidden.")
typer.echo(f"Group '{group_name}' is now hidden.")

View File

@ -1,14 +1,10 @@
"""module containing commands for hotkey management."""
import typer
from rich.console import Console
from rich.table import Table
from .alias import AliasGroup
app = typer.Typer(cls=AliasGroup)
out_console = Console()
err_console = Console(stderr=True)
@app.callback()
@ -22,14 +18,7 @@ def list(
):
"""List all hotkeys."""
resp = ctx.obj.get_hotkey_list()
table = Table(title='Hotkeys')
table.add_column('Name', justify='left', style='cyan')
for hotkey in resp.hotkeys:
table.add_row(hotkey)
out_console.print(table)
typer.echo('\n'.join(resp.hotkeys))
@app.command('trigger | tr')

View File

@ -3,15 +3,11 @@
from typing import Annotated
import typer
from rich.console import Console
from rich.table import Table
from . import util, validate
from . import validate
from .alias import AliasGroup
app = typer.Typer(cls=AliasGroup)
out_console = Console()
err_console = Console(stderr=True)
@app.callback()
@ -39,38 +35,18 @@ def list(
if not any([input, output, colour]):
kinds = ['input', 'output', 'color']
inputs = [
(input_.get('inputName'), input_.get('inputKind'))
for input_ in filter(
lambda input_: any(kind in input_.get('inputKind') for kind in kinds),
resp.inputs,
)
]
if not inputs:
err_console.print('No inputs found.')
raise typer.Exit(1)
table = Table(title='Inputs')
for column in ('Name', 'Kind'):
table.add_column(
column, justify='left' if column == 'Name' else 'center', style='cyan'
)
for input_name, input_kind in inputs:
table.add_row(
input_name,
util.snakecase_to_titlecase(input_kind),
)
out_console.print(table)
inputs = filter(
lambda input_: any(kind in input_.get('inputKind') for kind in kinds),
resp.inputs,
)
typer.echo('\n'.join(input_.get('inputName') for input_ in inputs))
@app.command('mute | m')
def mute(ctx: typer.Context, input_name: str):
"""Mute an input."""
if not validate.input_in_inputs(ctx, input_name):
err_console.print(f"Input '{input_name}' not found.")
typer.echo(f"Input '{input_name}' not found.", err=True)
raise typer.Exit(1)
ctx.obj.set_input_mute(
@ -78,14 +54,14 @@ def mute(ctx: typer.Context, input_name: str):
muted=True,
)
out_console.print(f"Input '{input_name}' muted.")
typer.echo(f"Input '{input_name}' muted.")
@app.command('unmute | um')
def unmute(ctx: typer.Context, input_name: str):
"""Unmute an input."""
if not validate.input_in_inputs(ctx, input_name):
err_console.print(f"Input '{input_name}' not found.")
typer.echo(f"Input '{input_name}' not found.", err=True)
raise typer.Exit(1)
ctx.obj.set_input_mute(
@ -93,16 +69,17 @@ def unmute(ctx: typer.Context, input_name: str):
muted=False,
)
out_console.print(f"Input '{input_name}' unmuted.")
typer.echo(f"Input '{input_name}' unmuted.")
@app.command('toggle | tg')
def toggle(ctx: typer.Context, input_name: str):
"""Toggle an input."""
if not validate.input_in_inputs(ctx, input_name):
err_console.print(f"Input '{input_name}' not found.")
typer.echo(f"Input '{input_name}' not found.", err=True)
raise typer.Exit(1)
# Get the current mute state
resp = ctx.obj.get_input_mute(name=input_name)
new_state = not resp.input_muted
@ -111,6 +88,6 @@ def toggle(ctx: typer.Context, input_name: str):
muted=new_state,
)
out_console.print(
typer.echo(
f"Input '{input_name}' {'muted' if new_state else 'unmuted'}.",
)

View File

@ -1,15 +1,11 @@
"""module containing commands for manipulating profiles in OBS."""
import typer
from rich.console import Console
from rich.table import Table
from . import validate
from .alias import AliasGroup
app = typer.Typer(cls=AliasGroup)
out_console = Console()
err_console = Console(stderr=True)
@app.callback()
@ -21,62 +17,52 @@ def main():
def list(ctx: typer.Context):
"""List profiles."""
resp = ctx.obj.get_profile_list()
table = Table(title='Profiles')
for column in ('Name', 'Current'):
table.add_column(
column, justify='left' if column == 'Name' else 'center', style='cyan'
)
for profile in resp.profiles:
table.add_row(
profile,
':heavy_check_mark:' if profile == resp.current_profile_name else '',
)
out_console.print(table)
typer.echo(profile)
@app.command('current | get')
def current(ctx: typer.Context):
"""Get the current profile."""
resp = ctx.obj.get_profile_list()
out_console.print(resp.current_profile_name)
typer.echo(resp.current_profile_name)
@app.command('switch | set')
def switch(ctx: typer.Context, profile_name: str):
"""Switch to a profile."""
if not validate.profile_exists(ctx, profile_name):
err_console.print(f"Profile '{profile_name}' not found.")
typer.echo(f"Profile '{profile_name}' not found.", err=True)
raise typer.Exit(1)
resp = ctx.obj.get_profile_list()
if resp.current_profile_name == profile_name:
err_console.print(f"Profile '{profile_name}' is already the current profile.")
typer.echo(
f"Profile '{profile_name}' is already the current profile.", err=True
)
raise typer.Exit(1)
ctx.obj.set_current_profile(profile_name)
out_console.print(f"Switched to profile '{profile_name}'.")
typer.echo(f"Switched to profile '{profile_name}'.")
@app.command('create | new')
def create(ctx: typer.Context, profile_name: str):
"""Create a new profile."""
if validate.profile_exists(ctx, profile_name):
err_console.print(f"Profile '{profile_name}' already exists.")
typer.echo(f"Profile '{profile_name}' already exists.", err=True)
raise typer.Exit(1)
ctx.obj.create_profile(profile_name)
out_console.print(f"Created profile '{profile_name}'.")
typer.echo(f"Created profile '{profile_name}'.")
@app.command('remove | rm')
def remove(ctx: typer.Context, profile_name: str):
"""Remove a profile."""
if not validate.profile_exists(ctx, profile_name):
err_console.print(f"Profile '{profile_name}' not found.")
typer.echo(f"Profile '{profile_name}' not found.", err=True)
raise typer.Exit(1)
ctx.obj.remove_profile(profile_name)
out_console.print(f"Removed profile '{profile_name}'.")
typer.echo(f"Removed profile '{profile_name}'.")

View File

@ -1,6 +0,0 @@
"""module contains utility functions for the obsws_cli package."""
def snakecase_to_titlecase(snake_str):
"""Convert a snake_case string to a title case string."""
return snake_str.replace('_', ' ').title()