Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pause controls #41

Merged
merged 1 commit into from Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -6,7 +6,8 @@
[![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://pkg.go.dev/github.com/muesli/obs-cli)

OBS-cli is a command-line remote control for OBS. It requires the
[obs-websocket](https://github.com/Palakis/obs-websocket) plugin to be installed on your system.
[obs-websocket](https://github.com/Palakis/obs-websocket) plugin to be installed
on your system.

## Installation

Expand Down Expand Up @@ -64,6 +65,14 @@ obs-cli recording stop
obs-cli recording toggle
```

Pause or resume a recording:

```
obs-cli recording pause enable
obs-cli recording pause resume
obs-cli recording pause toggle
```

Display recording status:

```
Expand Down
64 changes: 62 additions & 2 deletions recording.go
Expand Up @@ -21,7 +21,7 @@ var (
Use: "toggle",
Short: "Toggle recording",
RunE: func(cmd *cobra.Command, args []string) error {
return starStopRecording()
return startStopRecording()
},
}

Expand All @@ -41,6 +41,35 @@ var (
},
}

pauseRecordingCmd = &cobra.Command{
Use: "pause",
Short: "manage paused state",
}

enablePauseRecordingCmd = &cobra.Command{
Use: "enable",
Short: "Pause recording",
RunE: func(cmd *cobra.Command, args []string) error {
return pauseRecording()
},
}

resumePauseRecordingCmd = &cobra.Command{
Use: "resume",
Short: "Resume recording",
RunE: func(cmd *cobra.Command, args []string) error {
return resumeRecording()
},
}

togglePauseRecordingCmd = &cobra.Command{
Use: "toggle",
Short: "Pause/resume recording",
RunE: func(cmd *cobra.Command, args []string) error {
return pauseResumeRecording()
},
}

recordingStatusCmd = &cobra.Command{
Use: "status",
Short: "Reports recording status",
Expand All @@ -50,7 +79,7 @@ var (
}
)

func starStopRecording() error {
func startStopRecording() error {
_, err := client.Recording.StartStopRecording()
return err
}
Expand All @@ -65,6 +94,31 @@ func stopRecording() error {
return err
}

func pauseRecording() error {
_, err := client.Recording.PauseRecording()
return err
}

func resumeRecording() error {
_, err := client.Recording.ResumeRecording()
return err
}

func pauseResumeRecording() error {
r, err := client.Recording.GetRecordingStatus()
if err != nil {
return err
}
if !*r.IsRecording {
return fmt.Errorf("recording is not running")
}

if *r.IsRecordingPaused {
return resumeRecording()
}
return pauseRecording()
}

func recordingStatus() error {
r, err := client.Recording.GetRecordingStatus()
if err != nil {
Expand All @@ -90,9 +144,15 @@ func recordingStatus() error {
}

func init() {
pauseRecordingCmd.AddCommand(enablePauseRecordingCmd)
pauseRecordingCmd.AddCommand(resumePauseRecordingCmd)
pauseRecordingCmd.AddCommand(togglePauseRecordingCmd)

recordingCmd.AddCommand(startStopRecordingCmd)
recordingCmd.AddCommand(startRecordingCmd)
recordingCmd.AddCommand(stopRecordingCmd)
recordingCmd.AddCommand(pauseRecordingCmd)
recordingCmd.AddCommand(recordingStatusCmd)

rootCmd.AddCommand(recordingCmd)
}