Archived
1
0

fix thumbnailing and make it work

This commit is contained in:
Jeff Becker 2017-11-12 08:18:42 -05:00
parent feb43b1ed8
commit 936782b616
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
3 changed files with 20 additions and 13 deletions

View File

@ -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")

View File

@ -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")

View File

@ -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
}
}