From 936782b616f8921ee7e29e3ab79760eac21a742b Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 12 Nov 2017 08:18:42 -0500 Subject: [PATCH] fix thumbnailing and make it work --- contrib/backends/srndv2/src/srnd/config.go | 11 ++++++----- contrib/backends/srndv2/src/srnd/store.go | 17 +++++++++++------ contrib/backends/srndv2/src/srnd/thumbnails.go | 5 +++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/contrib/backends/srndv2/src/srnd/config.go b/contrib/backends/srndv2/src/srnd/config.go index 3265011..3d1db5c 100644 --- a/contrib/backends/srndv2/src/srnd/config.go +++ b/contrib/backends/srndv2/src/srnd/config.go @@ -224,16 +224,17 @@ func GenSRNdConfig() *configparser.Configuration { sect.Add("convert_bin", "/usr/bin/convert") sect.Add("ffmpegthumbnailer_bin", "/usr/bin/ffmpeg") sect.Add("sox_bin", "/usr/bin/sox") + sect.Add("identify_bin", "/usr/bin/identify") sect.Add("placeholder_thumbnail", "contrib/static/placeholder.png") sect.Add("compression", "0") // thumbnailing section sect = conf.NewSection("thumbnails") - sect.Add("image/*", "{{convert}} -thumbnail 200 {{infile}} {{outfile}}") - sect.Add("image/gif", "{{convert}} -thumbnail 200 {{infile}}[0] {{outfile}}") - sect.Add("audio/*", "{{ffmpeg}} -i {{infile}} -an -vcodec copy {{outfile}}") - sect.Add("video/*", "{{ffmpeg}} -i {{infile}} -vf scale=300:200 -vframes 1 {{outfile}}") - sect.Add("*", "cp {{placeholder}} {{outfile}}") + sect.Add("image/*", "{{.convert}} -thumbnail 200 {{.infile}} {{.outfile}}") + sect.Add("image/gif", "{{.convert}} -thumbnail 200 {{.infile}}[0] {{.outfile}}") + sect.Add("audio/*", "{{.ffmpeg}} -i {{.infile}} -an -vcodec copy {{.outfile}}") + sect.Add("video/*", "{{.ffmpeg}} -i {{.infile}} -vf scale=300:200 -vframes 1 {{.outfile}}") + sect.Add("*", "cp {{.placeholder}} {{.outfile}}") // database backend config sect = conf.NewSection("database") diff --git a/contrib/backends/srndv2/src/srnd/store.go b/contrib/backends/srndv2/src/srnd/store.go index deb0a60..498cff6 100644 --- a/contrib/backends/srndv2/src/srnd/store.go +++ b/contrib/backends/srndv2/src/srnd/store.go @@ -123,7 +123,7 @@ func createArticleStore(config map[string]string, thumbConfig *ThumbnailConfig, attachments: config["attachments_dir"], thumbs: config["thumbs_dir"], convert_path: config["convert_bin"], - identify_path: config["identify_path"], + identify_path: config["identify_bin"], ffmpeg_path: config["ffmpegthumbnailer_bin"], sox_path: config["sox_bin"], placeholder: config["placeholder_thumbnail"], @@ -165,6 +165,10 @@ func (self *articleStore) Init() { if !CheckFile(self.sox_path) { log.Fatal("connt find executable for sox: ", self.sox_path, " not found") } + if !CheckFile(self.identify_path) { + log.Fatal("cannot find executable for identify: ", self.identify_path, "not found") + } + if !CheckFile(self.placeholder) { log.Println("falling back to use default placeholder image") self.placeholder = "contrib/static/placeholder.png" @@ -245,7 +249,7 @@ func (self *articleStore) ThumbInfo(fpath string) (ThumbInfo, error) { } } } else { - log.Println("failed to determine size of thumbnail", err) + log.Println("failed to determine size of thumbnail", err, string(output)) } return info, err } @@ -261,10 +265,11 @@ func (self *articleStore) GenerateThumbnail(fname string) (info ThumbInfo, err e } infname := self.AttachmentFilepath(fname) err = self.thumbnails.GenerateThumbnail(infname, outfname, map[string]string{ - "ffmpeg": self.ffmpeg_path, - "convert": self.convert_path, - "sox": self.sox_path, - "identify": self.identify_path, + "ffmpeg": self.ffmpeg_path, + "convert": self.convert_path, + "sox": self.sox_path, + "identify": self.identify_path, + "placeholder": self.placeholder, }) if err != nil { log.Println(err.Error(), "so we'll use fallback thumbnailing") diff --git a/contrib/backends/srndv2/src/srnd/thumbnails.go b/contrib/backends/srndv2/src/srnd/thumbnails.go index b0678be..c1b6d0a 100644 --- a/contrib/backends/srndv2/src/srnd/thumbnails.go +++ b/contrib/backends/srndv2/src/srnd/thumbnails.go @@ -38,7 +38,7 @@ func (th *ThumbnailRule) GenerateThumbnail(infname, outfname string, env map[str } func (th *ThumbnailRule) Accepts(mimetype string) bool { - return regexp.MustCompile(th.AcceptsMimeType).MatchString(mimetype) + return th.AcceptsMimeType == "*" || regexp.MustCompilePOSIX(th.AcceptsMimeType).MatchString(mimetype) } func (th *ThumbnailConfig) Load(opts map[string]string) { @@ -60,7 +60,7 @@ func (th *ThumbnailConfig) Swap(i, j int) { } func (th *ThumbnailConfig) Less(i, j int) bool { - return th.rules[i].AcceptsMimeType < th.rules[j].AcceptsMimeType + return th.rules[i].AcceptsMimeType >= th.rules[j].AcceptsMimeType } func (th *ThumbnailConfig) FindRulesFor(mimetype string) (rules []ThumbnailRule) { @@ -78,6 +78,7 @@ func (th *ThumbnailConfig) GenerateThumbnail(infname, outfname string, env map[s for _, rule := range rules { err = rule.GenerateThumbnail(infname, outfname, env) if err == nil { + log.Println("made thumbnail for", infname) return } }