mirror of
https://github.com/onyx-and-iris/gobs-cli.git
synced 2026-01-11 08:27:51 +00:00
Compare commits
4 Commits
b0437b1656
...
ccf863c29a
| Author | SHA1 | Date | |
|---|---|---|---|
| ccf863c29a | |||
| fe8ac320ed | |||
| 7adf807d46 | |||
| dca8bc5ffc |
@ -5,7 +5,13 @@ 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.16.2] - 2026-01-26
|
# [0.17.0] - 2026-01-09
|
||||||
|
|
||||||
|
### 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
|
||||||
|
|
||||||
|
|||||||
38
README.md
38
README.md
@ -779,6 +779,44 @@ gobs-cli settings video
|
|||||||
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
|
||||||
|
|
||||||
|
|||||||
2
main.go
2
main.go
@ -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"`
|
||||||
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 {
|
type context struct {
|
||||||
|
|||||||
@ -6,24 +6,41 @@ import (
|
|||||||
"github.com/andreykaipov/goobs/api/requests/mediainputs"
|
"github.com/andreykaipov/goobs/api/requests/mediainputs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Mediainput represents a collection of commands to control media inputs.
|
// MediaCmd represents a collection of commands to control media inputs.
|
||||||
type Mediainput struct {
|
type MediaCmd struct {
|
||||||
SetCursor MediainputSetCursorCmd `cmd:"" help:"Sets the cursor position of a media input."`
|
Cursor MediaCursorCmd `cmd:"" help:"Get/set the cursor position of a media input."`
|
||||||
Play MediainputPlayCmd `cmd:"" help:"Plays a media input."`
|
Play MediaPlayCmd `cmd:"" help:"Plays a media input."`
|
||||||
Pause MediainputPauseCmd `cmd:"" help:"Pauses a media input."`
|
Pause MediaPauseCmd `cmd:"" help:"Pauses a media input."`
|
||||||
Stop MediainputStopCmd `cmd:"" help:"Stops a media input."`
|
Stop MediaStopCmd `cmd:"" help:"Stops a media input."`
|
||||||
Restart MediainputRestartCmd `cmd:"" help:"Restarts a media input."`
|
Restart MediaRestartCmd `cmd:"" help:"Restarts a media input."`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MediainputSetCursorCmd represents the command to set the cursor position of a media input.
|
// MediaCursorCmd represents the command to get or set the cursor position of a media input.
|
||||||
type MediainputSetCursorCmd struct {
|
type MediaCursorCmd 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)."`
|
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.
|
// 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 {
|
||||||
position, err := parseTimeStringToSeconds(cmd.TimeString)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to parse time string: %w", err)
|
return fmt.Errorf("failed to parse time string: %w", err)
|
||||||
}
|
}
|
||||||
@ -36,17 +53,23 @@ func (cmd *MediainputSetCursorCmd) 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.Fprintln(ctx.Out, "Set media input cursor to position (seconds):", position)
|
fmt.Fprintf(
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// MediainputPlayCmd represents the command to play a media input.
|
// MediaPlayCmd represents the command to play a media input.
|
||||||
type MediainputPlayCmd struct {
|
type MediaPlayCmd 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 *MediainputPlayCmd) Run(ctx *context) error {
|
func (cmd *MediaPlayCmd) Run(ctx *context) error {
|
||||||
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
|
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
|
||||||
mediainputs.NewTriggerMediaInputActionParams().
|
mediainputs.NewTriggerMediaInputActionParams().
|
||||||
WithInputName(cmd.InputName).
|
WithInputName(cmd.InputName).
|
||||||
@ -59,13 +82,13 @@ func (cmd *MediainputPlayCmd) Run(ctx *context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MediainputPauseCmd represents the command to pause a media input.
|
// MediaPauseCmd represents the command to pause a media input.
|
||||||
type MediainputPauseCmd struct {
|
type MediaPauseCmd 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 *MediainputPauseCmd) Run(ctx *context) error {
|
func (cmd *MediaPauseCmd) Run(ctx *context) error {
|
||||||
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
|
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
|
||||||
mediainputs.NewTriggerMediaInputActionParams().
|
mediainputs.NewTriggerMediaInputActionParams().
|
||||||
WithInputName(cmd.InputName).
|
WithInputName(cmd.InputName).
|
||||||
@ -78,13 +101,13 @@ func (cmd *MediainputPauseCmd) Run(ctx *context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MediainputStopCmd represents the command to stop a media input.
|
// MediaStopCmd represents the command to stop a media input.
|
||||||
type MediainputStopCmd struct {
|
type MediaStopCmd 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 *MediainputStopCmd) Run(ctx *context) error {
|
func (cmd *MediaStopCmd) Run(ctx *context) error {
|
||||||
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
|
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
|
||||||
mediainputs.NewTriggerMediaInputActionParams().
|
mediainputs.NewTriggerMediaInputActionParams().
|
||||||
WithInputName(cmd.InputName).
|
WithInputName(cmd.InputName).
|
||||||
@ -97,13 +120,13 @@ func (cmd *MediainputStopCmd) Run(ctx *context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MediainputRestartCmd represents the command to restart a media input.
|
// MediaRestartCmd represents the command to restart a media input.
|
||||||
type MediainputRestartCmd struct {
|
type MediaRestartCmd 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 *MediainputRestartCmd) Run(ctx *context) error {
|
func (cmd *MediaRestartCmd) Run(ctx *context) error {
|
||||||
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
|
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
|
||||||
mediainputs.NewTriggerMediaInputActionParams().
|
mediainputs.NewTriggerMediaInputActionParams().
|
||||||
WithInputName(cmd.InputName).
|
WithInputName(cmd.InputName).
|
||||||
16
util.go
16
util.go
@ -39,7 +39,7 @@ func trimPrefix(s, prefix string) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTimeStringToSeconds(timeStr string) (float64, error) {
|
func parseTimeStringToMilliseconds(timeStr string) (float64, error) {
|
||||||
parts := strings.Split(timeStr, ":")
|
parts := strings.Split(timeStr, ":")
|
||||||
var durationStr string
|
var durationStr string
|
||||||
|
|
||||||
@ -62,5 +62,17 @@ func parseTimeStringToSeconds(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(), nil
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user