3 Commits

Author SHA1 Message Date
cb75a2becf fix: use container duration instead of per-video-stream 2026-08-06 11:38:20 +02:00
e117522f3b chore: update module path and release 2026-08-06 11:07:15 +02:00
af6c7b3699 feat: add https safe file handling 2026-08-06 11:01:39 +02:00
4 changed files with 28 additions and 6 deletions

View File

@@ -6,7 +6,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
thumbnailgen "github.com/pablu23/thumbnail-gen" thumbnailgen "git.pablu.de/pablu/thumbnail-gen"
) )
var ( var (

View File

@@ -65,7 +65,7 @@ func (opts *Options) GetThumbnail(path string) ([][]byte, int, error) {
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)
@@ -137,7 +137,7 @@ func GetImage(buf *bytes.Buffer, path string, timestamp int, format string, scal
} }
func GetVideoLength(path string) (float64, error) { func GetVideoLength(path string) (float64, error) {
cmd := exec.Command("ffprobe", "-v", "quiet", "-select_streams", "v:0", "-show_entries", "stream=duration", "-of", "default=noprint_wrappers=1:nokey=1", path) cmd := exec.Command("ffprobe", "-v", "quiet", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", path)
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
cmd.Stdout = buf cmd.Stdout = buf
err := cmd.Run() err := cmd.Run()
@@ -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

2
go.mod
View File

@@ -1,3 +1,3 @@
module github.com/pablu23/thumbnail-gen module git.pablu.de/pablu/thumbnail-gen
go 1.22.4 go 1.22.4

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"