feat: add https safe file handling
This commit is contained in:
18
generator.go
18
generator.go
@@ -65,7 +65,7 @@ func (opts *Options) GetThumbnail(path string) ([][]byte, int, error) {
|
||||
if opts.UseSegments {
|
||||
interval = int(length / float64(opts.Segments))
|
||||
} else {
|
||||
interval = opts.Interval
|
||||
interval = opts.Interval
|
||||
}
|
||||
|
||||
return GetThumbnailUnderlying(path, opts.MaxThumbnails, filters, length, interval, opts.EnableFilter, opts.Format, opts.Scale)
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user