From f84e126381f11fda60ca79eccb63951fed35b287 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 9 Jan 2026 19:18:24 +0000 Subject: [PATCH] rename media-input to media replace set-cursor with cursor which can now get/set cursor position --- README.md | 20 ++++++++----- main.go | 2 +- mediainput.go => media.go | 63 +++++++++++++++++++++++++-------------- util.go | 12 ++++++++ 4 files changed, 66 insertions(+), 31 deletions(-) rename mediainput.go => media.go (61%) diff --git a/README.md b/README.md index 088c2f9..55f4ddf 100644 --- a/README.md +++ b/README.md @@ -779,36 +779,42 @@ gobs-cli settings video gobs-cli settings video --base-width=1920 --base-height=1080 ``` -### MediaInputCmd +### MediaCmd -- set-cursor: Sets the cursor position of a media input. +- set-cursor: Get/set the cursor position of a media input. + - args: InputName + + *optional* + - TimeString ```console -gobs-cli mediainput set-cursor "Media" "00:08:30" +gobs-cli media cursor "Media" + +gobs-cli media cursor "Media" "00:08:30" ``` - play: Plays a media input. ```console -gobs-cli mediainput play "Media" +gobs-cli media play "Media" ``` - pause: Pauses a media input. ```console -gobs-cli mediainput pause "Media" +gobs-cli media pause "Media" ``` - stop: Stops a media input. ```console -gobs-cli mediainput stop "Media" +gobs-cli media stop "Media" ``` - restart: Restarts a media input. ```console -gobs-cli mediainput restart "Media" +gobs-cli media restart "Media" ``` diff --git a/main.go b/main.go index 945b5cd..f161c73 100644 --- a/main.go +++ b/main.go @@ -72,7 +72,7 @@ type CLI struct { Projector ProjectorCmd `help:"Manage projectors." cmd:"" aliases:"prj" group:"Projector"` Screenshot ScreenshotCmd `help:"Take screenshots." cmd:"" aliases:"ss" group:"Screenshot"` Settings SettingsCmd `help:"Manage video and profile settings." cmd:"" aliases:"set" group:"Settings"` - Mediainput Mediainput `help:"Manage media inputs." cmd:"" aliases:"mi" group:"Media Input"` + Media MediaCmd `help:"Manage media inputs." cmd:"" aliases:"mi" group:"Media Input"` } type context struct { diff --git a/mediainput.go b/media.go similarity index 61% rename from mediainput.go rename to media.go index 0c30527..9857e8a 100644 --- a/mediainput.go +++ b/media.go @@ -6,23 +6,40 @@ import ( "github.com/andreykaipov/goobs/api/requests/mediainputs" ) -// Mediainput represents a collection of commands to control media inputs. -type Mediainput struct { - SetCursor MediainputSetCursorCmd `cmd:"" help:"Sets the cursor position of a media input."` - Play MediainputPlayCmd `cmd:"" help:"Plays a media input."` - Pause MediainputPauseCmd `cmd:"" help:"Pauses a media input."` - Stop MediainputStopCmd `cmd:"" help:"Stops a media input."` - Restart MediainputRestartCmd `cmd:"" help:"Restarts a media input."` +// MediaCmd represents a collection of commands to control media inputs. +type MediaCmd struct { + Cursor MediaCursorCmd `cmd:"" help:"Get/set the cursor position of a media input."` + Play MediaPlayCmd `cmd:"" help:"Plays a media input."` + Pause MediaPauseCmd `cmd:"" help:"Pauses a media input."` + Stop MediaStopCmd `cmd:"" help:"Stops a media input."` + Restart MediaRestartCmd `cmd:"" help:"Restarts a media input."` } -// MediainputSetCursorCmd represents the command to set the cursor position of a media input. -type MediainputSetCursorCmd struct { +// MediaCursorCmd represents the command to get or set the cursor position of a media input. +type MediaCursorCmd struct { 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)."` + 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:""` } // Run executes the command to set the cursor position of the media input. -func (cmd *MediainputSetCursorCmd) Run(ctx *context) error { +func (cmd *MediaCursorCmd) Run(ctx *context) error { + if 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 { return fmt.Errorf("failed to parse time string: %w", err) @@ -46,13 +63,13 @@ func (cmd *MediainputSetCursorCmd) Run(ctx *context) error { return nil } -// MediainputPlayCmd represents the command to play a media input. -type MediainputPlayCmd struct { +// MediaPlayCmd represents the command to play a media input. +type MediaPlayCmd struct { InputName string `arg:"" help:"Name of the media input."` } // Run executes the command to play the media input. -func (cmd *MediainputPlayCmd) Run(ctx *context) error { +func (cmd *MediaPlayCmd) Run(ctx *context) error { _, err := ctx.Client.MediaInputs.TriggerMediaInputAction( mediainputs.NewTriggerMediaInputActionParams(). WithInputName(cmd.InputName). @@ -65,13 +82,13 @@ func (cmd *MediainputPlayCmd) Run(ctx *context) error { return nil } -// MediainputPauseCmd represents the command to pause a media input. -type MediainputPauseCmd struct { +// MediaPauseCmd represents the command to pause a media input. +type MediaPauseCmd struct { InputName string `arg:"" help:"Name of the media input."` } // Run executes the command to pause the media input. -func (cmd *MediainputPauseCmd) Run(ctx *context) error { +func (cmd *MediaPauseCmd) Run(ctx *context) error { _, err := ctx.Client.MediaInputs.TriggerMediaInputAction( mediainputs.NewTriggerMediaInputActionParams(). WithInputName(cmd.InputName). @@ -84,13 +101,13 @@ func (cmd *MediainputPauseCmd) Run(ctx *context) error { return nil } -// MediainputStopCmd represents the command to stop a media input. -type MediainputStopCmd struct { +// MediaStopCmd represents the command to stop a media input. +type MediaStopCmd struct { InputName string `arg:"" help:"Name of the media input."` } // Run executes the command to stop the media input. -func (cmd *MediainputStopCmd) Run(ctx *context) error { +func (cmd *MediaStopCmd) Run(ctx *context) error { _, err := ctx.Client.MediaInputs.TriggerMediaInputAction( mediainputs.NewTriggerMediaInputActionParams(). WithInputName(cmd.InputName). @@ -103,13 +120,13 @@ func (cmd *MediainputStopCmd) Run(ctx *context) error { return nil } -// MediainputRestartCmd represents the command to restart a media input. -type MediainputRestartCmd struct { +// MediaRestartCmd represents the command to restart a media input. +type MediaRestartCmd struct { InputName string `arg:"" help:"Name of the media input."` } // Run executes the command to restart the media input. -func (cmd *MediainputRestartCmd) Run(ctx *context) error { +func (cmd *MediaRestartCmd) Run(ctx *context) error { _, err := ctx.Client.MediaInputs.TriggerMediaInputAction( mediainputs.NewTriggerMediaInputActionParams(). WithInputName(cmd.InputName). diff --git a/util.go b/util.go index f720df3..e3196f4 100644 --- a/util.go +++ b/util.go @@ -64,3 +64,15 @@ func parseTimeStringToMilliseconds(timeStr string) (float64, error) { return duration.Seconds() * 1000, 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) +}