Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Nov 10, 2023
1 parent 74a9ea7 commit 8667ec5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
21 changes: 20 additions & 1 deletion completers/ffmpeg_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,33 @@ func actionFlags() carapace.Action {
"-spre", "set the subtitle options to the indicated preset",
)
default:
return carapace.ActionValues()
switch c.Parts[0] {
case "-c":
return carapace.ActionValuesDescribed(
"a", "audio",
"v", "video",
)
default:
return carapace.ActionValues()
}
}
}).Tag("flags")
}

func actionFlagArguments(flag string) carapace.Action {
name := strings.SplitN(strings.TrimLeft(flag, "-"), ":", 2)[0]
switch name {
case "c":
switch flag {
case "-c:a":
// TODO audio codecs
return ffmpeg.ActionCodecs()
case "-c:v":
return ffmpeg.ActionCodecs()
// TODO video codecs
default:
return carapace.ActionValues()
}
case "h", "?", "help":
return carapace.ActionMultiPartsN("=", 2, func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
Expand Down
24 changes: 24 additions & 0 deletions pkg/actions/tools/ffmpeg/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ffmpeg

import (
"regexp"
"strings"

"github.com/rsteube/carapace"
)

func ActionCodecs() carapace.Action {
return carapace.ActionExecCommand("ffmpeg", "-hide_banner", "-codecs")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
r := regexp.MustCompile(`^.{7} (?P<codec>[^ ]+) +(?P<description>.*)$`)

vals := make([]string, 0)
for _, line := range lines[10 : len(lines)-1] {
if r.MatchString(line) {
matches := r.FindStringSubmatch(line)
vals = append(vals, matches[1], matches[2])
}
}
return carapace.ActionValuesDescribed(vals...)
})
}

0 comments on commit 8667ec5

Please sign in to comment.