From 39f1b0192631f43c97447f58602706e312622517 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 20 Jun 2025 01:32:36 +0100 Subject: [PATCH] add --uuid flags to input list, scene list and sceneitem list --- obsws_cli/input.py | 42 ++++++++++++----- obsws_cli/scene.py | 43 ++++++++++++++---- obsws_cli/sceneitem.py | 100 ++++++++++++++++++++++++++--------------- 3 files changed, 128 insertions(+), 57 deletions(-) diff --git a/obsws_cli/input.py b/obsws_cli/input.py index 45b5262..c950a62 100644 --- a/obsws_cli/input.py +++ b/obsws_cli/input.py @@ -27,6 +27,7 @@ def list_( colour: Annotated[bool, typer.Option(help='Filter by colour source type.')] = False, ffmpeg: Annotated[bool, typer.Option(help='Filter by ffmpeg source type.')] = False, vlc: Annotated[bool, typer.Option(help='Filter by VLC source type.')] = False, + uuid: Annotated[bool, typer.Option(help='Show UUIDs of scenes')] = False, ): """List all inputs.""" resp = ctx.obj.get_input_list() @@ -47,7 +48,7 @@ def list_( inputs = sorted( ( - (input_.get('inputName'), input_.get('inputKind')) + (input_.get('inputName'), input_.get('inputKind'), input_.get('inputUuid')) for input_ in filter( lambda input_: any(kind in input_.get('inputKind') for kind in kinds), resp.inputs, @@ -61,15 +62,24 @@ def list_( raise typer.Exit() table = Table(title='Inputs', padding=(0, 2)) - columns = [ - ('Input Name', 'left', 'cyan'), - ('Kind', 'center', 'cyan'), - ('Muted', 'center', None), - ] + if uuid: + columns = [ + ('Input Name', 'left', 'cyan'), + ('Kind', 'center', 'cyan'), + ('Muted', 'center', None), + ('UUID', 'left', 'cyan'), + ] + else: + table.title += ' (UUIDs hidden)' + columns = [ + ('Input Name', 'left', 'cyan'), + ('Kind', 'center', 'cyan'), + ('Muted', 'center', None), + ] for column, justify, style in columns: table.add_column(column, justify=justify, style=style) - for input_name, input_kind in inputs: + for input_name, input_kind, input_uuid in inputs: input_mark = '' if any( kind in input_kind @@ -78,11 +88,19 @@ def list_( input_muted = ctx.obj.get_input_mute(name=input_name).input_muted input_mark = ':white_heavy_check_mark:' if input_muted else ':x:' - table.add_row( - input_name, - util.snakecase_to_titlecase(input_kind), - input_mark, - ) + if uuid: + table.add_row( + input_name, + util.snakecase_to_titlecase(input_kind), + input_mark, + input_uuid, + ) + else: + table.add_row( + input_name, + util.snakecase_to_titlecase(input_kind), + input_mark, + ) out_console.print(table) diff --git a/obsws_cli/scene.py b/obsws_cli/scene.py index 48bcc46..c92acd7 100644 --- a/obsws_cli/scene.py +++ b/obsws_cli/scene.py @@ -20,7 +20,10 @@ def main(): @app.command('list | ls') -def list_(ctx: typer.Context): +def list_( + ctx: typer.Context, + uuid: Annotated[bool, typer.Option(help='Show UUIDs of scenes')] = False, +): """List all scenes.""" resp = ctx.obj.get_scene_list() scenes = ( @@ -28,19 +31,41 @@ def list_(ctx: typer.Context): for scene in reversed(resp.scenes) ) + active_scene = ctx.obj.get_current_program_scene().scene_name + table = Table(title='Scenes', padding=(0, 2)) - columns = [ - ('Scene Name', 'left', 'cyan'), - ('UUID', 'left', 'cyan'), - ] + if uuid: + columns = [ + ('Scene Name', 'left', 'cyan'), + ('Active', 'center', None), + ('UUID', 'left', 'cyan'), + ] + else: + table.title += ' (UUIDs hidden)' + columns = [ + ('Scene Name', 'left', 'cyan'), + ('Active', 'center', None), + ] for column, justify, style in columns: table.add_column(column, justify=justify, style=style) for scene_name, scene_uuid in scenes: - table.add_row( - scene_name, - scene_uuid, - ) + if scene_name == active_scene: + scene_output = f'[bold green]{scene_name}[/bold green]' + else: + scene_output = f'[dim]{scene_name}[/dim]' + + if uuid: + table.add_row( + scene_output, + ':white_heavy_check_mark:' if scene_name == active_scene else '', + scene_uuid, + ) + else: + table.add_row( + scene_output, + ':white_heavy_check_mark:' if scene_name == active_scene else '', + ) out_console.print(table) diff --git a/obsws_cli/sceneitem.py b/obsws_cli/sceneitem.py index 928fb24..806444b 100644 --- a/obsws_cli/sceneitem.py +++ b/obsws_cli/sceneitem.py @@ -2,7 +2,6 @@ from typing import Annotated, Optional -import obsws_python as obsws import typer from rich.console import Console from rich.table import Table @@ -30,6 +29,7 @@ def list_( help='Scene name to list items for', ), ] = None, + uuid: Annotated[bool, typer.Option(help='Show UUIDs of scene items')] = False, ): """List all items in a scene.""" if not scene_name: @@ -47,6 +47,7 @@ def list_( item.get('sourceName'), item.get('isGroup'), item.get('sceneItemEnabled'), + item.get('sourceUuid', 'N/A'), # Include source UUID ) for item in resp.scene_items ), @@ -58,17 +59,27 @@ def list_( raise typer.Exit() table = Table(title=f'Items in Scene: {scene_name}', padding=(0, 2)) - columns = [ - ('Item ID', 'center', 'cyan'), - ('Item Name', 'left', 'cyan'), - ('In Group', 'left', 'cyan'), - ('Enabled', 'center', None), - ] + if uuid: + columns = [ + ('Item ID', 'center', 'cyan'), + ('Item Name', 'left', 'cyan'), + ('In Group', 'left', 'cyan'), + ('Enabled', 'center', None), + ('UUID', 'left', 'cyan'), + ] + else: + table.title += ' (UUIDs hidden)' + columns = [ + ('Item ID', 'center', 'cyan'), + ('Item Name', 'left', 'cyan'), + ('In Group', 'left', 'cyan'), + ('Enabled', 'center', None), + ] # Add columns to the table for column, justify, style in columns: table.add_column(column, justify=justify, style=style) - for item_id, item_name, is_group, is_enabled in items: + for item_id, item_name, is_group, is_enabled, source_uuid in items: if is_group: resp = ctx.obj.get_group_scene_item_list(item_name) group_items = sorted( @@ -77,27 +88,53 @@ def list_( gi.get('sceneItemId'), gi.get('sourceName'), gi.get('sceneItemEnabled'), + gi.get('sourceUuid', 'N/A'), # Include source UUID ) for gi in resp.scene_items ), key=lambda x: x[0], # Sort by sceneItemId ) - for group_item_id, group_item_name, group_item_enabled in group_items: - table.add_row( - str(group_item_id), - group_item_name, - item_name, - ':white_heavy_check_mark:' - if is_enabled and group_item_enabled - else ':x:', - ) + for ( + group_item_id, + group_item_name, + group_item_enabled, + group_item_source_uuid, + ) in group_items: + if uuid: + table.add_row( + str(group_item_id), + group_item_name, + item_name, + ':white_heavy_check_mark:' + if is_enabled and group_item_enabled + else ':x:', + group_item_source_uuid, + ) + else: + table.add_row( + str(group_item_id), + group_item_name, + item_name, + ':white_heavy_check_mark:' + if is_enabled and group_item_enabled + else ':x:', + ) else: - table.add_row( - str(item_id), - item_name, - '', - ':white_heavy_check_mark:' if is_enabled else ':x:', - ) + if uuid: + table.add_row( + str(item_id), + item_name, + '', + ':white_heavy_check_mark:' if is_enabled else ':x:', + source_uuid, + ) + else: + table.add_row( + str(item_id), + item_name, + '', + ':white_heavy_check_mark:' if is_enabled else ':x:', + ) out_console.print(table) @@ -122,7 +159,9 @@ def _validate_sources( else: if not validate.item_in_scene_item_list(ctx, scene_name, item_name): err_console.print( - f'Item [yellow]{item_name}[/yellow] not found in scene [yellow]{scene_name}[/yellow].' + f'Item [yellow]{item_name}[/yellow] not found in scene [yellow]{scene_name}[/yellow]. Is the item in a group? ' + f'If so use the [yellow]--group[/yellow] option to specify the parent group.\n' + 'Use `obsws-cli sceneitem list` for a list of items in the scene.' ) return False @@ -146,18 +185,7 @@ def _get_scene_name_and_item_id( ) raise typer.Exit(1) else: - try: - resp = ctx.obj.get_scene_item_id(scene_name, item_name) - except obsws.error.OBSSDKRequestError as e: - if e.code == 600: - err_console.print( - f'Item [yellow]{item_name}[/yellow] not found in scene [yellow]{scene_name}[/yellow]. Is the item in a group? ' - 'If so use the --group option to specify the parent group. ' - 'Use `obsws-cli sceneitem list` for a list of items in the scene.' - ) - raise typer.Exit(1) - else: - raise + resp = ctx.obj.get_scene_item_id(scene_name, item_name) scene_item_id = resp.scene_item_id return scene_name, scene_item_id