Skip to content

Commit

Permalink
Add pause controls
Browse files Browse the repository at this point in the history
Fixes #31.
  • Loading branch information
muesli committed Dec 17, 2021
1 parent d539917 commit decf5b0
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
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)
}

0 comments on commit decf5b0

Please sign in to comment.