mirror of
https://github.com/onyx-and-iris/gobs-cli.git
synced 2026-01-15 18:37:48 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 88d41fd700 | |||
| eab9303af7 | |||
| 031d03a625 | |||
| f84e126381 | |||
| cb4898f2d4 | |||
| a652b44992 | |||
| f6fbf3c81f | |||
| f84908f668 | |||
| 3ffdf668ff |
@ -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/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
# [0.16.0] - 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
|
||||
|
||||
|
||||
63
README.md
63
README.md
@ -749,33 +749,74 @@ gobs-cli settings profile SimpleOutput VBitrate 6000
|
||||
```
|
||||
|
||||
- stream-service: Get/Set stream service setting.
|
||||
- args: Type
|
||||
- flags:
|
||||
- --key: Stream key.
|
||||
- --server: Stream server URL.
|
||||
|
||||
*optional*
|
||||
- args: Type
|
||||
|
||||
```console
|
||||
gobs-cli settings stream-service
|
||||
|
||||
gobs-cli settings stream-service rtmp_common --key='live_xyzxyzxyzxyz'
|
||||
gobs-cli settings stream-service --key='live_xyzxyzxyzxyz' rtmp_common
|
||||
```
|
||||
|
||||
- video: Get/Set video setting.
|
||||
- flags:
|
||||
- --show: Show video settings.
|
||||
- --base-width: Base (canvas) width.
|
||||
- --base-height: Base (canvas) height.
|
||||
- --output-width: Output (scaled) width.
|
||||
- --output-height: Output (scaled) height.
|
||||
- --fps-num: Frames per second numerator.
|
||||
- --fps-den: Frames per second denominator.
|
||||
- flags:
|
||||
|
||||
*optional*
|
||||
- --base-width: Base (canvas) width.
|
||||
- --base-height: Base (canvas) height.
|
||||
- --output-width: Output (scaled) width.
|
||||
- --output-height: Output (scaled) height.
|
||||
- --fps-num: Frames per second numerator.
|
||||
- --fps-den: Frames per second denominator.
|
||||
|
||||
```console
|
||||
gobs-cli settings video --show
|
||||
gobs-cli settings video
|
||||
|
||||
gobs-cli settings video --base-width=1920 --base-height=1080
|
||||
```
|
||||
|
||||
### MediaCmd
|
||||
|
||||
- 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
|
||||
|
||||
|
||||
1
main.go
1
main.go
@ -72,6 +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"`
|
||||
Media MediaCmd `help:"Manage media inputs." cmd:"" aliases:"mi" group:"Media Input"`
|
||||
}
|
||||
|
||||
type context struct {
|
||||
|
||||
140
media.go
Normal file
140
media.go
Normal file
@ -0,0 +1,140 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/andreykaipov/goobs/api/requests/mediainputs"
|
||||
)
|
||||
|
||||
// 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." aliases:"c"`
|
||||
Play MediaPlayCmd `cmd:"" help:"Plays a media input." aliases:"p"`
|
||||
Pause MediaPauseCmd `cmd:"" help:"Pauses a media input." aliases:"pa"`
|
||||
Stop MediaStopCmd `cmd:"" help:"Stops a media input." aliases:"s"`
|
||||
Restart MediaRestartCmd `cmd:"" help:"Restarts a media input." aliases:"r"`
|
||||
}
|
||||
|
||||
// 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). 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 *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)
|
||||
}
|
||||
|
||||
_, err = ctx.Client.MediaInputs.SetMediaInputCursor(
|
||||
mediainputs.NewSetMediaInputCursorParams().
|
||||
WithInputName(cmd.InputName).
|
||||
WithMediaCursor(position))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set media input cursor: %w", err)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// 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 *MediaPlayCmd) Run(ctx *context) error {
|
||||
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
|
||||
mediainputs.NewTriggerMediaInputActionParams().
|
||||
WithInputName(cmd.InputName).
|
||||
WithMediaAction("OBS_WEBSOCKET_MEDIA_INPUT_ACTION_PLAY"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to play media input: %w", err)
|
||||
}
|
||||
|
||||
fmt.Fprintln(ctx.Out, "Playing media input:", cmd.InputName)
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 *MediaPauseCmd) Run(ctx *context) error {
|
||||
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
|
||||
mediainputs.NewTriggerMediaInputActionParams().
|
||||
WithInputName(cmd.InputName).
|
||||
WithMediaAction("OBS_WEBSOCKET_MEDIA_INPUT_ACTION_PAUSE"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to pause media input: %w", err)
|
||||
}
|
||||
|
||||
fmt.Fprintln(ctx.Out, "Pausing media input:", cmd.InputName)
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 *MediaStopCmd) Run(ctx *context) error {
|
||||
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
|
||||
mediainputs.NewTriggerMediaInputActionParams().
|
||||
WithInputName(cmd.InputName).
|
||||
WithMediaAction("OBS_WEBSOCKET_MEDIA_INPUT_ACTION_STOP"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to stop media input: %w", err)
|
||||
}
|
||||
|
||||
fmt.Fprintln(ctx.Out, "Stopping media input:", cmd.InputName)
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 *MediaRestartCmd) Run(ctx *context) error {
|
||||
_, err := ctx.Client.MediaInputs.TriggerMediaInputAction(
|
||||
mediainputs.NewTriggerMediaInputActionParams().
|
||||
WithInputName(cmd.InputName).
|
||||
WithMediaAction("OBS_WEBSOCKET_MEDIA_INPUT_ACTION_RESTART"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to restart media input: %w", err)
|
||||
}
|
||||
|
||||
fmt.Fprintln(ctx.Out, "Restarting media input:", cmd.InputName)
|
||||
return nil
|
||||
}
|
||||
22
settings.go
22
settings.go
@ -189,7 +189,7 @@ func (cmd *SettingsProfileCmd) Run(ctx *context) error {
|
||||
|
||||
// SettingsStreamServiceCmd gets/ sets stream service settings.
|
||||
type SettingsStreamServiceCmd struct {
|
||||
Type string `arg:"" help:"Stream type (e.g., rtmp_common, rtmp_custom)." required:""`
|
||||
Type string `arg:"" help:"Stream type (e.g., rtmp_common, rtmp_custom)." optional:""`
|
||||
Key string ` help:"Stream key." 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)
|
||||
}
|
||||
|
||||
if cmd.Key == "" && cmd.Server == "" {
|
||||
if cmd.Type == "" {
|
||||
t := table.New().Border(lipgloss.RoundedBorder()).
|
||||
BorderStyle(lipgloss.NewStyle().Foreground(ctx.Style.border)).
|
||||
Headers("Stream Service Setting", "Value").
|
||||
@ -219,7 +219,7 @@ func (cmd *SettingsStreamServiceCmd) Run(ctx *context) error {
|
||||
return style
|
||||
})
|
||||
|
||||
t.Row("Type", cmd.Type)
|
||||
t.Row("Type", resp.StreamServiceType)
|
||||
t.Row("Key", resp.StreamServiceSettings.Key)
|
||||
t.Row("Server", resp.StreamServiceSettings.Server)
|
||||
|
||||
@ -252,13 +252,12 @@ func (cmd *SettingsStreamServiceCmd) Run(ctx *context) error {
|
||||
|
||||
// SettingsVideoCmd gets/ sets video settings.
|
||||
type SettingsVideoCmd struct {
|
||||
Show bool `flag:"" help:"Show video settings."`
|
||||
BaseWidth int `flag:"" help:"Base (canvas) width." min:"8"`
|
||||
BaseHeight int `flag:"" help:"Base (canvas) height." min:"8"`
|
||||
OutputWidth int `flag:"" help:"Output (scaled) width." min:"8"`
|
||||
OutputHeight int `flag:"" help:"Output (scaled) height." min:"8"`
|
||||
FPSNum int `flag:"" help:"Frames per second numerator." min:"1"`
|
||||
FPSDen int `flag:"" help:"Frames per second denominator." min:"1"`
|
||||
BaseWidth int `flag:"" help:"Base (canvas) width." min:"8"`
|
||||
BaseHeight int `flag:"" help:"Base (canvas) height." min:"8"`
|
||||
OutputWidth int `flag:"" help:"Output (scaled) width." min:"8"`
|
||||
OutputHeight int `flag:"" help:"Output (scaled) height." min:"8"`
|
||||
FPSNum int `flag:"" help:"Frames per second numerator." min:"1"`
|
||||
FPSDen int `flag:"" help:"Frames per second denominator." min:"1"`
|
||||
}
|
||||
|
||||
// Run executes the gets/ set video command.
|
||||
@ -269,7 +268,8 @@ func (cmd *SettingsVideoCmd) Run(ctx *context) error {
|
||||
return fmt.Errorf("failed to get video settings: %w", err)
|
||||
}
|
||||
|
||||
if cmd.Show {
|
||||
if cmd.BaseWidth == 0 && cmd.BaseHeight == 0 && cmd.OutputWidth == 0 &&
|
||||
cmd.OutputHeight == 0 && cmd.FPSNum == 0 && cmd.FPSDen == 0 {
|
||||
t := table.New().Border(lipgloss.RoundedBorder()).
|
||||
BorderStyle(lipgloss.NewStyle().Foreground(ctx.Style.border)).
|
||||
Headers("Video Setting", "Value").
|
||||
|
||||
40
util.go
40
util.go
@ -3,8 +3,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func snakeCaseToTitleCase(snake string) string {
|
||||
@ -36,3 +38,41 @@ func trimPrefix(s, prefix string) string {
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func parseTimeStringToMilliseconds(timeStr string) (float64, error) {
|
||||
parts := strings.Split(timeStr, ":")
|
||||
var durationStr string
|
||||
|
||||
switch len(parts) {
|
||||
case 1:
|
||||
// Format: SS -> "SSs"
|
||||
durationStr = parts[0] + "s"
|
||||
case 2:
|
||||
// Format: MM:SS -> "MMmSSs"
|
||||
durationStr = parts[0] + "m" + parts[1] + "s"
|
||||
case 3:
|
||||
// Format: HH:MM:SS -> "HHhMMmSSs"
|
||||
durationStr = parts[0] + "h" + parts[1] + "m" + parts[2] + "s"
|
||||
default:
|
||||
return 0, fmt.Errorf("invalid time format: %s", timeStr)
|
||||
}
|
||||
|
||||
duration, err := time.ParseDuration(durationStr)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to parse duration: %w", err)
|
||||
}
|
||||
|
||||
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