From 06cefe58ed369c2452722dbc3611a8e65c12f23f Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 23 Jun 2025 08:02:31 +0100 Subject: [PATCH] add record split and record chapter commands --- README.md | 15 +++++++++++ record.go | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 84 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 71ded75..16b4e3e 100644 --- a/README.md +++ b/README.md @@ -313,6 +313,21 @@ gobs-cli record directory "/home/me/obs-vids/" gobs-cli record directory "C:/Users/me/Videos" ``` +- split: Split recording. + +```console +gobs-cli record split +``` + +- chapter: Create a chapter in the recording. + + *optional* + - arg: ChapterName + +```console +gobs-cli record chapter "Chapter Name" +``` + ### StreamCmd - start: Start streaming. diff --git a/record.go b/record.go index f8604ee..3b670d4 100644 --- a/record.go +++ b/record.go @@ -4,17 +4,20 @@ import ( "fmt" "github.com/andreykaipov/goobs/api/requests/config" + "github.com/andreykaipov/goobs/api/requests/record" ) // RecordCmd handles the recording commands. type RecordCmd struct { - Start RecordStartCmd `cmd:"" help:"Start recording." aliases:"s"` - Stop RecordStopCmd `cmd:"" help:"Stop recording." aliases:"st"` - Toggle RecordToggleCmd `cmd:"" help:"Toggle recording." aliases:"tg"` - Status RecordStatusCmd `cmd:"" help:"Show recording status." aliases:"ss"` - Pause RecordPauseCmd `cmd:"" help:"Pause recording." aliases:"p"` - Resume RecordResumeCmd `cmd:"" help:"Resume recording." aliases:"r"` - Directory RecordDirectoryCmd `cmd:"" help:"Get/Set recording directory." aliases:"d"` + Start RecordStartCmd `cmd:"" help:"Start recording." aliases:"s"` + Stop RecordStopCmd `cmd:"" help:"Stop recording." aliases:"st"` + Toggle RecordToggleCmd `cmd:"" help:"Toggle recording." aliases:"tg"` + Status RecordStatusCmd `cmd:"" help:"Show recording status." aliases:"ss"` + Pause RecordPauseCmd `cmd:"" help:"Pause recording." aliases:"p"` + Resume RecordResumeCmd `cmd:"" help:"Resume recording." aliases:"r"` + Directory RecordDirectoryCmd `cmd:"" help:"Get/Set recording directory." aliases:"d"` + Split RecordSplitCmd `cmd:"" help:"Split recording." aliases:"sp"` + Chapter RecordChapterCmd `cmd:"" help:"Create a chapter in the recording." aliases:"c"` } // RecordStartCmd starts the recording. @@ -187,3 +190,62 @@ func (cmd *RecordDirectoryCmd) Run(ctx *context) error { fmt.Fprintf(ctx.Out, "Recording directory set to: %s\n", ctx.Style.Highlight(cmd.RecordDirectory)) return nil } + +// RecordSplitCmd splits the current recording. +type RecordSplitCmd struct{} // size = 0x0 + +// Run executes the command to split the recording. +func (cmd *RecordSplitCmd) Run(ctx *context) error { + status, err := ctx.Client.Record.GetRecordStatus() + if err != nil { + return err + } + + if !status.OutputActive { + return fmt.Errorf("recording is not in progress") + } + + _, err = ctx.Client.Record.SplitRecordFile() + if err != nil { + return err + } + + fmt.Fprintln(ctx.Out, "Recording split successfully.") + return nil +} + +// RecordChapterCmd creates a chapter in the recording. +type RecordChapterCmd struct { + ChapterName string `arg:"" help:"Name of the chapter to create." default:""` +} + +// Run executes the command to create a chapter in the recording. +func (cmd *RecordChapterCmd) Run(ctx *context) error { + status, err := ctx.Client.Record.GetRecordStatus() + if err != nil { + return err + } + + if !status.OutputActive { + return fmt.Errorf("recording is not in progress") + } + + var params *record.CreateRecordChapterParams + if cmd.ChapterName == "" { + params = record.NewCreateRecordChapterParams() + } else { + params = record.NewCreateRecordChapterParams().WithChapterName(cmd.ChapterName) + } + + _, err = ctx.Client.Record.CreateRecordChapter(params) + if err != nil { + return err + } + + if cmd.ChapterName == "" { + cmd.ChapterName = "unnamed" + } + + fmt.Fprintf(ctx.Out, "Chapter %s created successfully.\n", ctx.Style.Highlight(cmd.ChapterName)) + return nil +}