feat: add https safe file handling
This commit is contained in:
20
generator.go
20
generator.go
@@ -61,11 +61,11 @@ func (opts *Options) GetThumbnail(path string) ([][]byte, int, error) {
|
|||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var interval int
|
var interval int
|
||||||
if opts.UseSegments {
|
if opts.UseSegments {
|
||||||
interval = int(length / float64(opts.Segments))
|
interval = int(length / float64(opts.Segments))
|
||||||
} else {
|
} else {
|
||||||
interval = opts.Interval
|
interval = opts.Interval
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetThumbnailUnderlying(path, opts.MaxThumbnails, filters, length, interval, opts.EnableFilter, opts.Format, opts.Scale)
|
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)
|
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) {
|
func GetFilter(path string) ([]TimeFilter, error) {
|
||||||
buf := bytes.NewBuffer(nil)
|
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
|
cmd.Stdout = buf
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
// TODO: Replace with strings.Builder
|
// TODO: Replace with strings.Builder
|
||||||
|
|||||||
Reference in New Issue
Block a user