mirror of
https://github.com/onyx-and-iris/gobs-cli.git
synced 2026-01-15 10:27:49 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 88d41fd700 | |||
| eab9303af7 | |||
| 031d03a625 | |||
| f84e126381 | |||
| cb4898f2d4 | |||
| a652b44992 | |||
| f6fbf3c81f | |||
| f84908f668 | |||
| 3ffdf668ff | |||
| 6e37c2c6c7 | |||
| bc6cf46b98 | |||
| 51224583c8 |
@ -5,11 +5,18 @@ 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.15.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
|
### Added
|
||||||
|
|
||||||
- new subcommands added to input, see [InputCmd](https://github.com/onyx-and-iris/gobs-cli?tab=readme-ov-file#inputcmd)
|
- new subcommands added to input, see [InputCmd](https://github.com/onyx-and-iris/gobs-cli?tab=readme-ov-file#inputcmd)
|
||||||
|
- settings command group, see [SettingsCmd](https://github.com/onyx-and-iris/gobs-cli?tab=readme-ov-file#settingscmd)
|
||||||
|
|
||||||
# [0.14.1] - 2025-07-14
|
# [0.14.1] - 2025-07-14
|
||||||
|
|
||||||
|
|||||||
93
README.md
93
README.md
@ -725,6 +725,99 @@ gobs-cli projector open --monitor-index=1 "test_group"
|
|||||||
gobs-cli screenshot save --width=2560 --height=1440 "Scene" "C:\Users\me\Videos\screenshot.png"
|
gobs-cli screenshot save --width=2560 --height=1440 "Scene" "C:\Users\me\Videos\screenshot.png"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### SettingsCmd
|
||||||
|
|
||||||
|
- show: Show settings.
|
||||||
|
- flags:
|
||||||
|
|
||||||
|
*optional*
|
||||||
|
- --video: Show video settings.
|
||||||
|
- --record: Show record directory.
|
||||||
|
- --profile: Show profile parameters.
|
||||||
|
|
||||||
|
```console
|
||||||
|
gobs-cli settings show --video --record
|
||||||
|
```
|
||||||
|
|
||||||
|
- profile: Get/Set profile parameter setting.
|
||||||
|
- args: Category Name Value
|
||||||
|
|
||||||
|
```console
|
||||||
|
gobs-cli settings profile SimpleOutput VBitrate
|
||||||
|
|
||||||
|
gobs-cli settings profile SimpleOutput VBitrate 6000
|
||||||
|
```
|
||||||
|
|
||||||
|
- stream-service: Get/Set stream service setting.
|
||||||
|
- flags:
|
||||||
|
- --key: Stream key.
|
||||||
|
- --server: Stream server URL.
|
||||||
|
|
||||||
|
*optional*
|
||||||
|
- args: Type
|
||||||
|
|
||||||
|
```console
|
||||||
|
gobs-cli settings stream-service
|
||||||
|
|
||||||
|
gobs-cli settings stream-service --key='live_xyzxyzxyzxyz' rtmp_common
|
||||||
|
```
|
||||||
|
|
||||||
|
- video: Get/Set video setting.
|
||||||
|
- 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
|
||||||
|
|
||||||
|
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
|
## License
|
||||||
|
|
||||||
`gobs-cli` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
`gobs-cli` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
||||||
|
|||||||
2
main.go
2
main.go
@ -71,6 +71,8 @@ type CLI struct {
|
|||||||
Filter FilterCmd `help:"Manage filters." cmd:"" aliases:"f" group:"Filter"`
|
Filter FilterCmd `help:"Manage filters." cmd:"" aliases:"f" group:"Filter"`
|
||||||
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"`
|
||||||
|
Media MediaCmd `help:"Manage media inputs." cmd:"" aliases:"mi" group:"Media Input"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type context struct {
|
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
|
||||||
|
}
|
||||||
334
settings.go
Normal file
334
settings.go
Normal file
@ -0,0 +1,334 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/andreykaipov/goobs/api/requests/config"
|
||||||
|
"github.com/andreykaipov/goobs/api/typedefs"
|
||||||
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
"github.com/charmbracelet/lipgloss/table"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SettingsCmd handles settings management.
|
||||||
|
type SettingsCmd struct {
|
||||||
|
Show SettingsShowCmd `help:"Show settings." cmd:"" aliases:"s"`
|
||||||
|
Profile SettingsProfileCmd `help:"Get/Set profile parameter setting." cmd:"" aliases:"p"`
|
||||||
|
StreamService SettingsStreamServiceCmd `help:"Get/Set stream service setting." cmd:"" aliases:"ss"`
|
||||||
|
Video SettingsVideoCmd `help:"Get/Set video setting." cmd:"" aliases:"v"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SettingsShowCmd shows the video settings.
|
||||||
|
type SettingsShowCmd struct {
|
||||||
|
Video bool `flag:"" help:"Show video settings."`
|
||||||
|
Record bool `flag:"" help:"Show record directory."`
|
||||||
|
Profile bool `flag:"" help:"Show profile parameters."`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run executes the show command.
|
||||||
|
// nolint: misspell
|
||||||
|
func (cmd *SettingsShowCmd) Run(ctx *context) error {
|
||||||
|
if !cmd.Video && !cmd.Record && !cmd.Profile {
|
||||||
|
cmd.Video = true
|
||||||
|
cmd.Record = true
|
||||||
|
cmd.Profile = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get video settings
|
||||||
|
videoResp, err := ctx.Client.Config.GetVideoSettings()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get video settings: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
vt := table.New().Border(lipgloss.RoundedBorder()).
|
||||||
|
BorderStyle(lipgloss.NewStyle().Foreground(ctx.Style.border)).
|
||||||
|
Headers("Video Setting", "Value").
|
||||||
|
StyleFunc(func(row, _ int) lipgloss.Style {
|
||||||
|
style := lipgloss.NewStyle().Padding(0, 3)
|
||||||
|
switch {
|
||||||
|
case row == table.HeaderRow:
|
||||||
|
style = style.Bold(true).Align(lipgloss.Center)
|
||||||
|
case row%2 == 0:
|
||||||
|
style = style.Foreground(ctx.Style.evenRows)
|
||||||
|
default:
|
||||||
|
style = style.Foreground(ctx.Style.oddRows)
|
||||||
|
}
|
||||||
|
return style
|
||||||
|
})
|
||||||
|
|
||||||
|
vt.Row("Base Width", fmt.Sprintf("%.0f", videoResp.BaseWidth))
|
||||||
|
vt.Row("Base Height", fmt.Sprintf("%.0f", videoResp.BaseHeight))
|
||||||
|
vt.Row("Output Width", fmt.Sprintf("%.0f", videoResp.OutputWidth))
|
||||||
|
vt.Row("Output Height", fmt.Sprintf("%.0f", videoResp.OutputHeight))
|
||||||
|
vt.Row("FPS Numerator", fmt.Sprintf("%.0f", videoResp.FpsNumerator))
|
||||||
|
vt.Row("FPS Denominator", fmt.Sprintf("%.0f", videoResp.FpsDenominator))
|
||||||
|
|
||||||
|
// Get record directory
|
||||||
|
dirResp, err := ctx.Client.Config.GetRecordDirectory()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get record directory: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
rt := table.New().Border(lipgloss.RoundedBorder()).
|
||||||
|
BorderStyle(lipgloss.NewStyle().Foreground(ctx.Style.border)).
|
||||||
|
Headers("Record Setting", "Value").
|
||||||
|
StyleFunc(func(row, _ int) lipgloss.Style {
|
||||||
|
style := lipgloss.NewStyle().Padding(0, 3)
|
||||||
|
switch {
|
||||||
|
case row == table.HeaderRow:
|
||||||
|
style = style.Bold(true).Align(lipgloss.Center)
|
||||||
|
case row%2 == 0:
|
||||||
|
style = style.Foreground(ctx.Style.evenRows)
|
||||||
|
default:
|
||||||
|
style = style.Foreground(ctx.Style.oddRows)
|
||||||
|
}
|
||||||
|
return style
|
||||||
|
})
|
||||||
|
|
||||||
|
rt.Row("Directory", dirResp.RecordDirectory)
|
||||||
|
|
||||||
|
// Get profile prameters
|
||||||
|
pt := table.New().Border(lipgloss.RoundedBorder()).
|
||||||
|
BorderStyle(lipgloss.NewStyle().Foreground(ctx.Style.border)).
|
||||||
|
Headers("Profile Parameter", "Value").
|
||||||
|
StyleFunc(func(row, _ int) lipgloss.Style {
|
||||||
|
style := lipgloss.NewStyle().Padding(0, 3)
|
||||||
|
switch {
|
||||||
|
case row == table.HeaderRow:
|
||||||
|
style = style.Bold(true).Align(lipgloss.Center)
|
||||||
|
case row%2 == 0:
|
||||||
|
style = style.Foreground(ctx.Style.evenRows)
|
||||||
|
default:
|
||||||
|
style = style.Foreground(ctx.Style.oddRows)
|
||||||
|
}
|
||||||
|
return style
|
||||||
|
})
|
||||||
|
|
||||||
|
// Common profile parameters to display
|
||||||
|
params := []struct {
|
||||||
|
category string
|
||||||
|
name string
|
||||||
|
label string
|
||||||
|
}{
|
||||||
|
{"Output", "Mode", "Output Mode"},
|
||||||
|
|
||||||
|
{"SimpleOutput", "StreamEncoder", "Simple Streaming Encoder"},
|
||||||
|
{"SimpleOutput", "RecEncoder", "Simple Recording Encoder"},
|
||||||
|
{"SimpleOutput", "RecFormat2", "Simple Recording Video Format"},
|
||||||
|
{"SimpleOutput", "RecAudioEncoder", "Simple Recording Audio Format"},
|
||||||
|
{"SimpleOutput", "RecQuality", "Simple Recording Quality"},
|
||||||
|
|
||||||
|
{"AdvOut", "Encoder", "Advanced Streaming Encoder"},
|
||||||
|
{"AdvOut", "RecEncoder", "Advanced Recording Encoder"},
|
||||||
|
{"AdvOut", "RecType", "Advanced Recording Type"},
|
||||||
|
{"AdvOut", "RecFormat2", "Advanced Recording Video Format"},
|
||||||
|
{"AdvOut", "RecAudioEncoder", "Advanced Recording Audio Format"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, param := range params {
|
||||||
|
resp, err := ctx.Client.Config.GetProfileParameter(
|
||||||
|
config.NewGetProfileParameterParams().
|
||||||
|
WithParameterCategory(param.category).
|
||||||
|
WithParameterName(param.name),
|
||||||
|
)
|
||||||
|
if err == nil && resp.ParameterValue != "" {
|
||||||
|
pt.Row(param.label, resp.ParameterValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmd.Video {
|
||||||
|
fmt.Fprintln(ctx.Out, vt.Render())
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmd.Record {
|
||||||
|
fmt.Fprintln(ctx.Out, rt.Render())
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmd.Profile {
|
||||||
|
fmt.Fprintln(ctx.Out, pt.Render())
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SettingsProfileCmd gets/ sets a profile parameter.
|
||||||
|
type SettingsProfileCmd struct {
|
||||||
|
Category string `arg:"" help:"Parameter category (e.g., AdvOut, SimpleOutput, Output)." required:""`
|
||||||
|
Name string `arg:"" help:"Parameter name (e.g., RecFormat2, RecEncoder)." required:""`
|
||||||
|
Value string `arg:"" help:"Parameter value to set." optional:""`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run executes the set command.
|
||||||
|
func (cmd *SettingsProfileCmd) Run(ctx *context) error {
|
||||||
|
if cmd.Value == "" {
|
||||||
|
resp, err := ctx.Client.Config.GetProfileParameter(
|
||||||
|
config.NewGetProfileParameterParams().
|
||||||
|
WithParameterCategory(cmd.Category).
|
||||||
|
WithParameterName(cmd.Name),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get parameter %s.%s: %w", cmd.Category, cmd.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(ctx.Out, "%s.%s = %s\n", cmd.Category, cmd.Name, resp.ParameterValue)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := ctx.Client.Config.SetProfileParameter(
|
||||||
|
config.NewSetProfileParameterParams().
|
||||||
|
WithParameterCategory(cmd.Category).
|
||||||
|
WithParameterName(cmd.Name).
|
||||||
|
WithParameterValue(cmd.Value),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to set parameter %s.%s: %w", cmd.Category, cmd.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(ctx.Out, "Set %s.%s = %s\n", cmd.Category, cmd.Name, cmd.Value)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SettingsStreamServiceCmd gets/ sets stream service settings.
|
||||||
|
type SettingsStreamServiceCmd struct {
|
||||||
|
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:""`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run executes the set stream service command.
|
||||||
|
// nolint: misspell
|
||||||
|
func (cmd *SettingsStreamServiceCmd) Run(ctx *context) error {
|
||||||
|
resp, err := ctx.Client.Config.GetStreamServiceSettings()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get stream service settings: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmd.Type == "" {
|
||||||
|
t := table.New().Border(lipgloss.RoundedBorder()).
|
||||||
|
BorderStyle(lipgloss.NewStyle().Foreground(ctx.Style.border)).
|
||||||
|
Headers("Stream Service Setting", "Value").
|
||||||
|
StyleFunc(func(row, _ int) lipgloss.Style {
|
||||||
|
style := lipgloss.NewStyle().Padding(0, 3)
|
||||||
|
switch {
|
||||||
|
case row == table.HeaderRow:
|
||||||
|
style = style.Bold(true).Align(lipgloss.Center)
|
||||||
|
case row%2 == 0:
|
||||||
|
style = style.Foreground(ctx.Style.evenRows)
|
||||||
|
default:
|
||||||
|
style = style.Foreground(ctx.Style.oddRows)
|
||||||
|
}
|
||||||
|
return style
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Row("Type", resp.StreamServiceType)
|
||||||
|
t.Row("Key", resp.StreamServiceSettings.Key)
|
||||||
|
t.Row("Server", resp.StreamServiceSettings.Server)
|
||||||
|
|
||||||
|
fmt.Fprintln(ctx.Out, t.Render())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmd.Key == "" {
|
||||||
|
cmd.Key = resp.StreamServiceSettings.Key
|
||||||
|
}
|
||||||
|
if cmd.Server == "" {
|
||||||
|
cmd.Server = resp.StreamServiceSettings.Server
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = ctx.Client.Config.SetStreamServiceSettings(
|
||||||
|
config.NewSetStreamServiceSettingsParams().
|
||||||
|
WithStreamServiceSettings(&typedefs.StreamServiceSettings{
|
||||||
|
Key: cmd.Key,
|
||||||
|
Server: cmd.Server,
|
||||||
|
}).
|
||||||
|
WithStreamServiceType(cmd.Type),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to set stream service settings: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintln(ctx.Out, "Stream service settings updated successfully.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SettingsVideoCmd gets/ sets video settings.
|
||||||
|
type SettingsVideoCmd struct {
|
||||||
|
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.
|
||||||
|
// nolint: misspell
|
||||||
|
func (cmd *SettingsVideoCmd) Run(ctx *context) error {
|
||||||
|
resp, err := ctx.Client.Config.GetVideoSettings()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get video settings: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
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").
|
||||||
|
StyleFunc(func(row, _ int) lipgloss.Style {
|
||||||
|
style := lipgloss.NewStyle().Padding(0, 3)
|
||||||
|
switch {
|
||||||
|
case row == table.HeaderRow:
|
||||||
|
style = style.Bold(true).Align(lipgloss.Center)
|
||||||
|
case row%2 == 0:
|
||||||
|
style = style.Foreground(ctx.Style.evenRows)
|
||||||
|
default:
|
||||||
|
style = style.Foreground(ctx.Style.oddRows)
|
||||||
|
}
|
||||||
|
return style
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Row("Base Width", fmt.Sprintf("%.0f", resp.BaseWidth))
|
||||||
|
t.Row("Base Height", fmt.Sprintf("%.0f", resp.BaseHeight))
|
||||||
|
t.Row("Output Width", fmt.Sprintf("%.0f", resp.OutputWidth))
|
||||||
|
t.Row("Output Height", fmt.Sprintf("%.0f", resp.OutputHeight))
|
||||||
|
t.Row("FPS Numerator", fmt.Sprintf("%.0f", resp.FpsNumerator))
|
||||||
|
t.Row("FPS Denominator", fmt.Sprintf("%.0f", resp.FpsDenominator))
|
||||||
|
|
||||||
|
fmt.Fprintln(ctx.Out, t.Render())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmd.BaseWidth == 0 {
|
||||||
|
cmd.BaseWidth = int(resp.BaseWidth)
|
||||||
|
}
|
||||||
|
if cmd.BaseHeight == 0 {
|
||||||
|
cmd.BaseHeight = int(resp.BaseHeight)
|
||||||
|
}
|
||||||
|
if cmd.OutputWidth == 0 {
|
||||||
|
cmd.OutputWidth = int(resp.OutputWidth)
|
||||||
|
}
|
||||||
|
if cmd.OutputHeight == 0 {
|
||||||
|
cmd.OutputHeight = int(resp.OutputHeight)
|
||||||
|
}
|
||||||
|
if cmd.FPSNum == 0 {
|
||||||
|
cmd.FPSNum = int(resp.FpsNumerator)
|
||||||
|
}
|
||||||
|
if cmd.FPSDen == 0 {
|
||||||
|
cmd.FPSDen = int(resp.FpsDenominator)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = ctx.Client.Config.SetVideoSettings(
|
||||||
|
config.NewSetVideoSettingsParams().
|
||||||
|
WithBaseWidth(float64(cmd.BaseWidth)).
|
||||||
|
WithBaseHeight(float64(cmd.BaseHeight)).
|
||||||
|
WithOutputWidth(float64(cmd.OutputWidth)).
|
||||||
|
WithOutputHeight(float64(cmd.OutputHeight)).
|
||||||
|
WithFpsNumerator(float64(cmd.FPSNum)).
|
||||||
|
WithFpsDenominator(float64(cmd.FPSDen)),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to set video settings: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintln(ctx.Out, "Video settings updated successfully.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
40
util.go
40
util.go
@ -3,8 +3,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func snakeCaseToTitleCase(snake string) string {
|
func snakeCaseToTitleCase(snake string) string {
|
||||||
@ -36,3 +38,41 @@ func trimPrefix(s, prefix string) string {
|
|||||||
}
|
}
|
||||||
return s
|
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