mirror of
https://github.com/onyx-and-iris/gobs-cli.git
synced 2025-06-09 13:10:35 +01:00
add ScreenshotCmd
This commit is contained in:
parent
ee47832cd6
commit
29fe6fedfb
1
main.go
1
main.go
@ -47,6 +47,7 @@ type CLI struct {
|
||||
Hotkey HotkeyCmd `help:"Manage hotkeys." cmd:"" aliases:"hk"`
|
||||
Filter FilterCmd `help:"Manage filters." cmd:"" aliases:"f"`
|
||||
Projector ProjectorCmd `help:"Manage projectors." cmd:"" aliases:"prj"`
|
||||
Screenshot ScreenshotCmd `help:"Take screenshots." cmd:"" aliases:"ss"`
|
||||
}
|
||||
|
||||
type context struct {
|
||||
|
41
screenshot.go
Normal file
41
screenshot.go
Normal file
@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/andreykaipov/goobs/api/requests/sources"
|
||||
)
|
||||
|
||||
// ScreenshotCmd provides commands to manage screenshots in OBS Studio.
|
||||
type ScreenshotCmd struct {
|
||||
Save ScreenshotSaveCmd `cmd:"" help:"Take a screenshot and save it to a file." aliases:"sv"`
|
||||
}
|
||||
|
||||
// ScreenshotSaveCmd represents the command to save a screenshot of a source in OBS.
|
||||
type ScreenshotSaveCmd struct {
|
||||
SourceName string `arg:"" help:"Name of the source to take a screenshot of."`
|
||||
FilePath string `arg:"" help:"Path to the file where the screenshot will be saved."`
|
||||
Width float64 ` help:"Width of the screenshot in pixels." flag:"" default:"1920"`
|
||||
Height float64 ` help:"Height of the screenshot in pixels." flag:"" default:"1080"`
|
||||
Quality float64 ` help:"Quality of the screenshot (1-100)." flag:"" default:"-1"`
|
||||
}
|
||||
|
||||
// Run executes the command to take a screenshot and save it to a file.
|
||||
func (cmd *ScreenshotSaveCmd) Run(ctx *context) error {
|
||||
_, err := ctx.Client.Sources.SaveSourceScreenshot(
|
||||
sources.NewSaveSourceScreenshotParams().
|
||||
WithSourceName(cmd.SourceName).
|
||||
WithImageFormat(trimPrefix(filepath.Ext(cmd.FilePath), ".")).
|
||||
WithImageFilePath(cmd.FilePath).
|
||||
WithImageWidth(cmd.Width).
|
||||
WithImageHeight(cmd.Height).
|
||||
WithImageCompressionQuality(cmd.Quality),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to take screenshot: %w", err)
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx.Out, "Screenshot saved to %s.\n", cmd.FilePath)
|
||||
return nil
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user