Compare commits

..

1 Commits

Author SHA1 Message Date
6eb8a5ffed implement mediainput command group
note, set-cursor not currently working, possible bug in goobs
2026-01-08 20:38:36 +00:00
6 changed files with 51 additions and 133 deletions

View File

@@ -5,13 +5,7 @@ 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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
# [0.17.0] - 2026-01-09 # [0.16.0] - 2026-01-26
### Added
- media command group, see [MediaCmd](https://github.com/onyx-and-iris/gobs-cli?tab=readme-ov-file#mediacmd)
# [0.16.2] - 2026-01-08
### Added ### Added

View File

@@ -749,23 +749,20 @@ gobs-cli settings profile SimpleOutput VBitrate 6000
``` ```
- stream-service: Get/Set stream service setting. - stream-service: Get/Set stream service setting.
- args: Type
- flags: - flags:
- --key: Stream key. - --key: Stream key.
- --server: Stream server URL. - --server: Stream server URL.
*optional*
- args: Type
```console ```console
gobs-cli settings stream-service gobs-cli settings stream-service
gobs-cli settings stream-service --key='live_xyzxyzxyzxyz' rtmp_common gobs-cli settings stream-service rtmp_common --key='live_xyzxyzxyzxyz'
``` ```
- video: Get/Set video setting. - video: Get/Set video setting.
- flags: - flags:
- --show: Show video settings.
*optional*
- --base-width: Base (canvas) width. - --base-width: Base (canvas) width.
- --base-height: Base (canvas) height. - --base-height: Base (canvas) height.
- --output-width: Output (scaled) width. - --output-width: Output (scaled) width.
@@ -774,49 +771,11 @@ gobs-cli settings stream-service --key='live_xyzxyzxyzxyz' rtmp_common
- --fps-den: Frames per second denominator. - --fps-den: Frames per second denominator.
```console ```console
gobs-cli settings video gobs-cli settings video --show
gobs-cli settings video --base-width=1920 --base-height=1080 gobs-cli settings video --base-width=1920 --base-height=1080
``` ```
### MediaCmd
- set-cursor: Get/set the cursor position of a media input.
- args: InputName
*optional*
- TimeString
```console
gobs-cli media cursor "Media"
gobs-cli media cursor "Media" "00:08:30"
```
- play: Plays a media input.
```console
gobs-cli media play "Media"
```
- pause: Pauses a media input.
```console
gobs-cli media pause "Media"
```
- stop: Stops a media input.
```console
gobs-cli media stop "Media"
```
- restart: Restarts a media input.
```console
gobs-cli media restart "Media"
```
## License ## License

View File

@@ -72,7 +72,7 @@ type CLI struct {
Projector ProjectorCmd `help:"Manage projectors." cmd:"" aliases:"prj" group:"Projector"` Projector ProjectorCmd `help:"Manage projectors." cmd:"" aliases:"prj" group:"Projector"`
Screenshot ScreenshotCmd `help:"Take screenshots." cmd:"" aliases:"ss" group:"Screenshot"` Screenshot ScreenshotCmd `help:"Take screenshots." cmd:"" aliases:"ss" group:"Screenshot"`
Settings SettingsCmd `help:"Manage video and profile settings." cmd:"" aliases:"set" group:"Settings"` Settings SettingsCmd `help:"Manage video and profile settings." cmd:"" aliases:"set" group:"Settings"`
Media MediaCmd `help:"Manage media inputs." cmd:"" aliases:"mi" group:"Media Input"` Mediainput Mediainput `help:"Manage media inputs." cmd:"" aliases:"mi" group:"Media Input"`
} }
type context struct { type context struct {

View File

@@ -6,41 +6,24 @@ import (
"github.com/andreykaipov/goobs/api/requests/mediainputs" "github.com/andreykaipov/goobs/api/requests/mediainputs"
) )
// MediaCmd represents a collection of commands to control media inputs. // Mediainput represents a collection of commands to control media inputs.
type MediaCmd struct { type Mediainput struct {
Cursor MediaCursorCmd `cmd:"" help:"Get/set the cursor position of a media input."` SetCursor MediainputSetCursorCmd `cmd:"" help:"Sets the cursor position of a media input."`
Play MediaPlayCmd `cmd:"" help:"Plays a media input."` Play MediainputPlayCmd `cmd:"" help:"Plays a media input."`
Pause MediaPauseCmd `cmd:"" help:"Pauses a media input."` Pause MediainputPauseCmd `cmd:"" help:"Pauses a media input."`
Stop MediaStopCmd `cmd:"" help:"Stops a media input."` Stop MediainputStopCmd `cmd:"" help:"Stops a media input."`
Restart MediaRestartCmd `cmd:"" help:"Restarts a media input."` Restart MediainputRestartCmd `cmd:"" help:"Restarts a media input."`
} }
// MediaCursorCmd represents the command to get or set the cursor position of a media input. // MediainputSetCursorCmd represents the command to set the cursor position of a media input.
type MediaCursorCmd struct { type MediainputSetCursorCmd struct {
InputName string `arg:"" help:"Name of the media input."` InputName string `arg:"" help:"Name of the media input."`
TimeString string `arg:"" help:"Time position to set the cursor to (e.g., '00:01:30' for 1 minute 30 seconds). If not provided, the current cursor position will be displayed." optional:""` TimeString string `arg:"" help:"Time position to set the cursor to (e.g., '00:01:30' for 1 minute 30 seconds)."`
} }
// Run executes the command to set the cursor position of the media input. // Run executes the command to set the cursor position of the media input.
func (cmd *MediaCursorCmd) Run(ctx *context) error { func (cmd *MediainputSetCursorCmd) Run(ctx *context) error {
if cmd.TimeString == "" { position, err := parseTimeStringToSeconds(cmd.TimeString)
resp, err := ctx.Client.MediaInputs.GetMediaInputStatus(
mediainputs.NewGetMediaInputStatusParams().
WithInputName(cmd.InputName))
if err != nil {
return fmt.Errorf("failed to get media input cursor: %w", err)
}
fmt.Fprintf(
ctx.Out,
"%s cursor position: %s\n",
ctx.Style.Highlight(cmd.InputName),
formatMillisecondsToTimeString(resp.MediaCursor),
)
return nil
}
position, err := parseTimeStringToMilliseconds(cmd.TimeString)
if err != nil { if err != nil {
return fmt.Errorf("failed to parse time string: %w", err) return fmt.Errorf("failed to parse time string: %w", err)
} }
@@ -53,23 +36,17 @@ func (cmd *MediaCursorCmd) Run(ctx *context) error {
return fmt.Errorf("failed to set media input cursor: %w", err) return fmt.Errorf("failed to set media input cursor: %w", err)
} }
fmt.Fprintf( fmt.Fprintln(ctx.Out, "Set media input cursor to position (seconds):", position)
ctx.Out,
"Set %s cursor to %s (%.0f ms)\n",
ctx.Style.Highlight(cmd.InputName),
ctx.Style.Highlight(cmd.TimeString),
position,
)
return nil return nil
} }
// MediaPlayCmd represents the command to play a media input. // MediainputPlayCmd represents the command to play a media input.
type MediaPlayCmd struct { type MediainputPlayCmd struct {
InputName string `arg:"" help:"Name of the media input."` InputName string `arg:"" help:"Name of the media input."`
} }
// Run executes the command to play the media input. // Run executes the command to play the media input.
func (cmd *MediaPlayCmd) Run(ctx *context) error { func (cmd *MediainputPlayCmd) Run(ctx *context) error {
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction( _, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
mediainputs.NewTriggerMediaInputActionParams(). mediainputs.NewTriggerMediaInputActionParams().
WithInputName(cmd.InputName). WithInputName(cmd.InputName).
@@ -82,13 +59,13 @@ func (cmd *MediaPlayCmd) Run(ctx *context) error {
return nil return nil
} }
// MediaPauseCmd represents the command to pause a media input. // MediainputPauseCmd represents the command to pause a media input.
type MediaPauseCmd struct { type MediainputPauseCmd struct {
InputName string `arg:"" help:"Name of the media input."` InputName string `arg:"" help:"Name of the media input."`
} }
// Run executes the command to pause the media input. // Run executes the command to pause the media input.
func (cmd *MediaPauseCmd) Run(ctx *context) error { func (cmd *MediainputPauseCmd) Run(ctx *context) error {
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction( _, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
mediainputs.NewTriggerMediaInputActionParams(). mediainputs.NewTriggerMediaInputActionParams().
WithInputName(cmd.InputName). WithInputName(cmd.InputName).
@@ -101,13 +78,13 @@ func (cmd *MediaPauseCmd) Run(ctx *context) error {
return nil return nil
} }
// MediaStopCmd represents the command to stop a media input. // MediainputStopCmd represents the command to stop a media input.
type MediaStopCmd struct { type MediainputStopCmd struct {
InputName string `arg:"" help:"Name of the media input."` InputName string `arg:"" help:"Name of the media input."`
} }
// Run executes the command to stop the media input. // Run executes the command to stop the media input.
func (cmd *MediaStopCmd) Run(ctx *context) error { func (cmd *MediainputStopCmd) Run(ctx *context) error {
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction( _, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
mediainputs.NewTriggerMediaInputActionParams(). mediainputs.NewTriggerMediaInputActionParams().
WithInputName(cmd.InputName). WithInputName(cmd.InputName).
@@ -120,13 +97,13 @@ func (cmd *MediaStopCmd) Run(ctx *context) error {
return nil return nil
} }
// MediaRestartCmd represents the command to restart a media input. // MediainputRestartCmd represents the command to restart a media input.
type MediaRestartCmd struct { type MediainputRestartCmd struct {
InputName string `arg:"" help:"Name of the media input."` InputName string `arg:"" help:"Name of the media input."`
} }
// Run executes the command to restart the media input. // Run executes the command to restart the media input.
func (cmd *MediaRestartCmd) Run(ctx *context) error { func (cmd *MediainputRestartCmd) Run(ctx *context) error {
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction( _, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
mediainputs.NewTriggerMediaInputActionParams(). mediainputs.NewTriggerMediaInputActionParams().
WithInputName(cmd.InputName). WithInputName(cmd.InputName).

View File

@@ -189,7 +189,7 @@ func (cmd *SettingsProfileCmd) Run(ctx *context) error {
// SettingsStreamServiceCmd gets/ sets stream service settings. // SettingsStreamServiceCmd gets/ sets stream service settings.
type SettingsStreamServiceCmd struct { type SettingsStreamServiceCmd struct {
Type string `arg:"" help:"Stream type (e.g., rtmp_common, rtmp_custom)." optional:""` Type string `arg:"" help:"Stream type (e.g., rtmp_common, rtmp_custom)." required:""`
Key string ` help:"Stream key." flag:""` Key string ` help:"Stream key." flag:""`
Server string ` help:"Stream server URL." flag:""` Server string ` help:"Stream server URL." flag:""`
} }
@@ -202,7 +202,7 @@ func (cmd *SettingsStreamServiceCmd) Run(ctx *context) error {
return fmt.Errorf("failed to get stream service settings: %w", err) return fmt.Errorf("failed to get stream service settings: %w", err)
} }
if cmd.Type == "" { if cmd.Key == "" && cmd.Server == "" {
t := table.New().Border(lipgloss.RoundedBorder()). t := table.New().Border(lipgloss.RoundedBorder()).
BorderStyle(lipgloss.NewStyle().Foreground(ctx.Style.border)). BorderStyle(lipgloss.NewStyle().Foreground(ctx.Style.border)).
Headers("Stream Service Setting", "Value"). Headers("Stream Service Setting", "Value").
@@ -219,7 +219,7 @@ func (cmd *SettingsStreamServiceCmd) Run(ctx *context) error {
return style return style
}) })
t.Row("Type", resp.StreamServiceType) t.Row("Type", cmd.Type)
t.Row("Key", resp.StreamServiceSettings.Key) t.Row("Key", resp.StreamServiceSettings.Key)
t.Row("Server", resp.StreamServiceSettings.Server) t.Row("Server", resp.StreamServiceSettings.Server)
@@ -252,6 +252,7 @@ func (cmd *SettingsStreamServiceCmd) Run(ctx *context) error {
// SettingsVideoCmd gets/ sets video settings. // SettingsVideoCmd gets/ sets video settings.
type SettingsVideoCmd struct { type SettingsVideoCmd struct {
Show bool `flag:"" help:"Show video settings."`
BaseWidth int `flag:"" help:"Base (canvas) width." min:"8"` BaseWidth int `flag:"" help:"Base (canvas) width." min:"8"`
BaseHeight int `flag:"" help:"Base (canvas) height." min:"8"` BaseHeight int `flag:"" help:"Base (canvas) height." min:"8"`
OutputWidth int `flag:"" help:"Output (scaled) width." min:"8"` OutputWidth int `flag:"" help:"Output (scaled) width." min:"8"`
@@ -268,8 +269,7 @@ func (cmd *SettingsVideoCmd) Run(ctx *context) error {
return fmt.Errorf("failed to get video settings: %w", err) return fmt.Errorf("failed to get video settings: %w", err)
} }
if cmd.BaseWidth == 0 && cmd.BaseHeight == 0 && cmd.OutputWidth == 0 && if cmd.Show {
cmd.OutputHeight == 0 && cmd.FPSNum == 0 && cmd.FPSDen == 0 {
t := table.New().Border(lipgloss.RoundedBorder()). t := table.New().Border(lipgloss.RoundedBorder()).
BorderStyle(lipgloss.NewStyle().Foreground(ctx.Style.border)). BorderStyle(lipgloss.NewStyle().Foreground(ctx.Style.border)).
Headers("Video Setting", "Value"). Headers("Video Setting", "Value").

16
util.go
View File

@@ -39,7 +39,7 @@ func trimPrefix(s, prefix string) string {
return s return s
} }
func parseTimeStringToMilliseconds(timeStr string) (float64, error) { func parseTimeStringToSeconds(timeStr string) (float64, error) {
parts := strings.Split(timeStr, ":") parts := strings.Split(timeStr, ":")
var durationStr string var durationStr string
@@ -62,17 +62,5 @@ func parseTimeStringToMilliseconds(timeStr string) (float64, error) {
return 0, fmt.Errorf("failed to parse duration: %w", err) return 0, fmt.Errorf("failed to parse duration: %w", err)
} }
return duration.Seconds() * 1000, nil return duration.Seconds(), nil
}
func formatMillisecondsToTimeString(ms float64) string {
totalSeconds := int(ms / 1000)
hours := totalSeconds / 3600
minutes := (totalSeconds % 3600) / 60
seconds := totalSeconds % 60
if hours > 0 {
return fmt.Sprintf("%02d:%02d:%02d", hours, minutes, seconds)
}
return fmt.Sprintf("%02d:%02d", minutes, seconds)
} }