From 90aa5d4423eabe1443cb9b99de6872ed5157b4a4 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sun, 25 May 2025 11:55:45 +0100 Subject: [PATCH] add filter commands upd README, CHANGELOG --- CHANGELOG.md | 6 +++ README.md | 37 +++++++++++++ filter.go | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 1 + 4 files changed, 193 insertions(+) create mode 100644 filter.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cfbc62..bf7471e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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.6.0] - 2025-05-25 + +### Added + +- filter commands, see [Filter](https://github.com/onyx-and-iris/gobs-cli?tab=readme-ov-file#filter) + # [0.5.0] - 2025-05-22 ### Added diff --git a/README.md b/README.md index a1e4436..184cede 100644 --- a/README.md +++ b/README.md @@ -477,5 +477,42 @@ gobs-cli hotkey trigger-sequence OBS_KEY_F1 --ctrl gobs-cli hotkey trigger-sequence OBS_KEY_F1 --shift --ctrl ``` +### FilterCmd + +- list: List all filters. + +```console +gobs-cli filter list +``` + +- enable: Enable filter. + - args: SourceName FilterName + +```console +gobs-cli enable 'Mic/Aux' 'Gain' +``` + +- disable: Disable filter. + - args: SourceName FilterName + +```console +gobs-cli disable 'Mic/Aux' 'Gain' +``` + +- toggle: Toggle filter. + - args: SourceName FilterName + +```console +gobs-cli toggle 'Mic/Aux' 'Gain' +``` + +- status: Get filter status. + - args: SourceName FilterName + +```console +gobs-cli status 'Mic/Aux' 'Gain' +``` + + [userconfigdir]: https://pkg.go.dev/os#UserConfigDir [obs-keyids]: https://github.com/obsproject/obs-studio/blob/master/libobs/obs-hotkeys.h \ No newline at end of file diff --git a/filter.go b/filter.go new file mode 100644 index 0000000..76c8ef0 --- /dev/null +++ b/filter.go @@ -0,0 +1,149 @@ +package main + +import ( + "fmt" + + "github.com/andreykaipov/goobs/api/requests/filters" +) + +// FilterCmd provides commands to manage filters in OBS Studio. +type FilterCmd struct { + List FilterListCmd `cmd:"" help:"List all filters." aliases:"ls"` + Enable FilterEnableCmd `cmd:"" help:"Enable filter." aliases:"on"` + Disable FilterDisableCmd `cmd:"" help:"Disable filter." aliases:"off"` + Toggle FilterToggleCmd `cmd:"" help:"Toggle filter." aliases:"tg"` + Status FilterStatusCmd `cmd:"" help:"Get filter status." aliases:"ss"` +} + +// FilterListCmd provides a command to list all filters in a scene. +type FilterListCmd struct { + SourceName string `arg:"" help:"Name of the source to list filters from."` +} + +// Run executes the command to list all filters in a scene. +func (cmd *FilterListCmd) Run(ctx *context) error { + filters, err := ctx.Client.Filters.GetSourceFilterList( + filters.NewGetSourceFilterListParams().WithSourceName(cmd.SourceName), + ) + if err != nil { + return err + } + for _, filter := range filters.Filters { + fmt.Fprintf(ctx.Out, "Name: %s\n Kind: %s\n Enabled: %t\n Settings: %+v\n", + filter.FilterName, filter.FilterKind, filter.FilterEnabled, filter.FilterSettings) + } + return nil +} + +// FilterEnableCmd provides a command to enable a filter in a scene. +type FilterEnableCmd struct { + SourceName string `arg:"" help:"Name of the source to enable filter from."` + FilterName string `arg:"" help:"Name of the filter to enable."` +} + +// Run executes the command to enable a filter in a scene. +func (cmd *FilterEnableCmd) Run(ctx *context) error { + _, err := ctx.Client.Filters.SetSourceFilterEnabled( + filters.NewSetSourceFilterEnabledParams(). + WithSourceName(cmd.SourceName). + WithFilterName(cmd.FilterName). + WithFilterEnabled(true), + ) + if err != nil { + return fmt.Errorf("failed to enable filter %s on source %s: %w", + cmd.FilterName, cmd.SourceName, err) + } + fmt.Fprintf(ctx.Out, "Filter %s enabled on source %s.\n", + cmd.FilterName, cmd.SourceName) + return nil +} + +// FilterDisableCmd provides a command to disable a filter in a scene. +type FilterDisableCmd struct { + SourceName string `arg:"" help:"Name of the source to disable filter from."` + FilterName string `arg:"" help:"Name of the filter to disable."` +} + +// Run executes the command to disable a filter in a scene. +func (cmd *FilterDisableCmd) Run(ctx *context) error { + _, err := ctx.Client.Filters.SetSourceFilterEnabled( + filters.NewSetSourceFilterEnabledParams(). + WithSourceName(cmd.SourceName). + WithFilterName(cmd.FilterName). + WithFilterEnabled(false), + ) + if err != nil { + return fmt.Errorf("failed to disable filter %s on source %s: %w", + cmd.FilterName, cmd.SourceName, err) + } + fmt.Fprintf(ctx.Out, "Filter %s disabled on source %s.\n", + cmd.FilterName, cmd.SourceName) + return nil +} + +// FilterToggleCmd provides a command to toggle a filter in a scene. +type FilterToggleCmd struct { + SourceName string `arg:"" help:"Name of the source to toggle filter from."` + FilterName string `arg:"" help:"Name of the filter to toggle."` +} + +// Run executes the command to toggle a filter in a scene. +func (cmd *FilterToggleCmd) Run(ctx *context) error { + filter, err := ctx.Client.Filters.GetSourceFilter( + filters.NewGetSourceFilterParams(). + WithSourceName(cmd.SourceName). + WithFilterName(cmd.FilterName), + ) + if err != nil { + return fmt.Errorf("failed to get filter %s on source %s: %w", + cmd.FilterName, cmd.SourceName, err) + } + + newStatus := !filter.FilterEnabled + _, err = ctx.Client.Filters.SetSourceFilterEnabled( + filters.NewSetSourceFilterEnabledParams(). + WithSourceName(cmd.SourceName). + WithFilterName(cmd.FilterName). + WithFilterEnabled(newStatus), + ) + if err != nil { + return fmt.Errorf("failed to toggle filter %s on source %s: %w", + cmd.FilterName, cmd.SourceName, err) + } + + if newStatus { + fmt.Fprintf(ctx.Out, "Filter %s on source %s is now enabled.\n", + cmd.FilterName, cmd.SourceName) + } else { + fmt.Fprintf(ctx.Out, "Filter %s on source %s is now disabled.\n", + cmd.FilterName, cmd.SourceName) + } + return nil +} + +// FilterStatusCmd provides a command to get the status of a filter in a scene. +type FilterStatusCmd struct { + SourceName string `arg:"" help:"Name of the source to get filter status from."` + FilterName string `arg:"" help:"Name of the filter to get status."` +} + +// Run executes the command to get the status of a filter in a scene. +func (cmd *FilterStatusCmd) Run(ctx *context) error { + filter, err := ctx.Client.Filters.GetSourceFilter( + filters.NewGetSourceFilterParams(). + WithSourceName(cmd.SourceName). + WithFilterName(cmd.FilterName), + ) + if err != nil { + return fmt.Errorf("failed to get status of filter %s on source %s: %w", + cmd.FilterName, cmd.SourceName, err) + } + if filter.FilterEnabled { + fmt.Fprintf(ctx.Out, "Filter %s on source %s is enabled.\n", + cmd.FilterName, cmd.SourceName) + } else { + fmt.Fprintf(ctx.Out, "Filter %s on source %s is disabled.\n", + cmd.FilterName, cmd.SourceName) + } + return nil +} diff --git a/main.go b/main.go index c77d679..12794f4 100644 --- a/main.go +++ b/main.go @@ -44,6 +44,7 @@ type CLI struct { Studiomode StudioModeCmd `help:"Manage studio mode." cmd:"" aliases:"sm"` Virtualcam VirtualCamCmd `help:"Manage virtual camera." cmd:"" aliases:"vc"` Hotkey HotkeyCmd `help:"Manage hotkeys." cmd:"" aliases:"hk"` + Filter FilterCmd `help:"Manage filters." cmd:"" aliases:"f"` } type context struct {