feat: add https safe file handling

This commit is contained in:
2026-08-06 10:58:29 +02:00
parent 13de03cd1c
commit af6c7b3699
2 changed files with 25 additions and 3 deletions

View File

@@ -148,9 +148,23 @@ func GetVideoLength(path string) (float64, error) {
return strconv.ParseFloat(strings.ReplaceAll(buf.String(), "\n", ""), 64)
}
func escapeFilterValue(value string) string {
return strings.NewReplacer(
"\\", "\\\\",
"'", "\\'",
":", "\\:",
",", "\\,",
";", "\\;",
"[", "\\[",
"]", "\\]",
).Replace(value)
}
func GetFilter(path string) ([]TimeFilter, error) {
buf := bytes.NewBuffer(nil)
cmd := exec.Command("ffprobe", "-f", "lavfi", "-i", fmt.Sprintf("movie=%s,blackdetect[out0]", path), "-show_entries", "tags=lavfi.black_start,lavfi.black_end", "-of", "default=nw=1", "-v", "quiet")
filter := fmt.Sprintf("movie=filename='%s',blackdetect[out0]", escapeFilterValue(path))
cmd := exec.Command("ffprobe", "-f", "lavfi", "-i", filter, "-show_entries", "tags=lavfi.black_start,lavfi.black_end", "-of", "default=nw=1", "-v", "quiet")
cmd.Stdout = buf
err := cmd.Run()
// TODO: Replace with strings.Builder

8
mise.toml Normal file
View File

@@ -0,0 +1,8 @@
[tools]
go = "1.26.0"
"go:golang.org/x/tools/gopls" = "latest"
buf = "1.72.0"
[tasks.generate]
description = "Generate Go protobuf and gRPC bindings"
run = "buf generate"