fix thumbnailing and make it work
This commit is contained in:
parent
feb43b1ed8
commit
936782b616
@ -224,16 +224,17 @@ func GenSRNdConfig() *configparser.Configuration {
|
|||||||
sect.Add("convert_bin", "/usr/bin/convert")
|
sect.Add("convert_bin", "/usr/bin/convert")
|
||||||
sect.Add("ffmpegthumbnailer_bin", "/usr/bin/ffmpeg")
|
sect.Add("ffmpegthumbnailer_bin", "/usr/bin/ffmpeg")
|
||||||
sect.Add("sox_bin", "/usr/bin/sox")
|
sect.Add("sox_bin", "/usr/bin/sox")
|
||||||
|
sect.Add("identify_bin", "/usr/bin/identify")
|
||||||
sect.Add("placeholder_thumbnail", "contrib/static/placeholder.png")
|
sect.Add("placeholder_thumbnail", "contrib/static/placeholder.png")
|
||||||
sect.Add("compression", "0")
|
sect.Add("compression", "0")
|
||||||
|
|
||||||
// thumbnailing section
|
// thumbnailing section
|
||||||
sect = conf.NewSection("thumbnails")
|
sect = conf.NewSection("thumbnails")
|
||||||
sect.Add("image/*", "{{convert}} -thumbnail 200 {{infile}} {{outfile}}")
|
sect.Add("image/*", "{{.convert}} -thumbnail 200 {{.infile}} {{.outfile}}")
|
||||||
sect.Add("image/gif", "{{convert}} -thumbnail 200 {{infile}}[0] {{outfile}}")
|
sect.Add("image/gif", "{{.convert}} -thumbnail 200 {{.infile}}[0] {{.outfile}}")
|
||||||
sect.Add("audio/*", "{{ffmpeg}} -i {{infile}} -an -vcodec copy {{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("video/*", "{{.ffmpeg}} -i {{.infile}} -vf scale=300:200 -vframes 1 {{.outfile}}")
|
||||||
sect.Add("*", "cp {{placeholder}} {{outfile}}")
|
sect.Add("*", "cp {{.placeholder}} {{.outfile}}")
|
||||||
|
|
||||||
// database backend config
|
// database backend config
|
||||||
sect = conf.NewSection("database")
|
sect = conf.NewSection("database")
|
||||||
|
@ -123,7 +123,7 @@ func createArticleStore(config map[string]string, thumbConfig *ThumbnailConfig,
|
|||||||
attachments: config["attachments_dir"],
|
attachments: config["attachments_dir"],
|
||||||
thumbs: config["thumbs_dir"],
|
thumbs: config["thumbs_dir"],
|
||||||
convert_path: config["convert_bin"],
|
convert_path: config["convert_bin"],
|
||||||
identify_path: config["identify_path"],
|
identify_path: config["identify_bin"],
|
||||||
ffmpeg_path: config["ffmpegthumbnailer_bin"],
|
ffmpeg_path: config["ffmpegthumbnailer_bin"],
|
||||||
sox_path: config["sox_bin"],
|
sox_path: config["sox_bin"],
|
||||||
placeholder: config["placeholder_thumbnail"],
|
placeholder: config["placeholder_thumbnail"],
|
||||||
@ -165,6 +165,10 @@ func (self *articleStore) Init() {
|
|||||||
if !CheckFile(self.sox_path) {
|
if !CheckFile(self.sox_path) {
|
||||||
log.Fatal("connt find executable for sox: ", self.sox_path, " not found")
|
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) {
|
if !CheckFile(self.placeholder) {
|
||||||
log.Println("falling back to use default placeholder image")
|
log.Println("falling back to use default placeholder image")
|
||||||
self.placeholder = "contrib/static/placeholder.png"
|
self.placeholder = "contrib/static/placeholder.png"
|
||||||
@ -245,7 +249,7 @@ func (self *articleStore) ThumbInfo(fpath string) (ThumbInfo, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Println("failed to determine size of thumbnail", err)
|
log.Println("failed to determine size of thumbnail", err, string(output))
|
||||||
}
|
}
|
||||||
return info, err
|
return info, err
|
||||||
}
|
}
|
||||||
@ -265,6 +269,7 @@ func (self *articleStore) GenerateThumbnail(fname string) (info ThumbInfo, err e
|
|||||||
"convert": self.convert_path,
|
"convert": self.convert_path,
|
||||||
"sox": self.sox_path,
|
"sox": self.sox_path,
|
||||||
"identify": self.identify_path,
|
"identify": self.identify_path,
|
||||||
|
"placeholder": self.placeholder,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error(), "so we'll use fallback thumbnailing")
|
log.Println(err.Error(), "so we'll use fallback thumbnailing")
|
||||||
|
@ -38,7 +38,7 @@ func (th *ThumbnailRule) GenerateThumbnail(infname, outfname string, env map[str
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (th *ThumbnailRule) Accepts(mimetype string) bool {
|
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) {
|
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 {
|
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) {
|
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 {
|
for _, rule := range rules {
|
||||||
err = rule.GenerateThumbnail(infname, outfname, env)
|
err = rule.GenerateThumbnail(infname, outfname, env)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
log.Println("made thumbnail for", infname)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user