Don't generate new thumbnails if they already exist

This commit is contained in:
James Mills 2020-03-22 18:42:35 +10:00
parent 7492a150eb
commit 8ae65e4b73
No known key found for this signature in database
GPG key ID: AC4C014F1440EBD6
2 changed files with 18 additions and 4 deletions

View file

@ -79,11 +79,14 @@ func ParseVideo(p *Path, name string) (*Video, error) {
v.Thumb = pic.Data v.Thumb = pic.Data
v.ThumbType = pic.MIMEType v.ThumbType = pic.MIMEType
} else if utils.CmdExists("mt") { } else if utils.CmdExists("mt") {
thumbFn := fmt.Sprintf("%s.jpg", strings.TrimSuffix(pth, filepath.Ext(pth)))
if !utils.FileExists(thumbFn) {
if err := utils.RunCmd(10, "mt", "-s", "-n", "1", pth); err != nil { if err := utils.RunCmd(10, "mt", "-s", "-n", "1", pth); err != nil {
err := fmt.Errorf("error generating thumbnail: %w", err) err := fmt.Errorf("error generating thumbnail: %w", err)
log.Error(err.Error()) log.Error(err.Error())
return nil, err return nil, err
} }
}
data, err := ioutil.ReadFile(fmt.Sprintf("%s.jpg", strings.TrimSuffix(pth, filepath.Ext(pth)))) data, err := ioutil.ReadFile(fmt.Sprintf("%s.jpg", strings.TrimSuffix(pth, filepath.Ext(pth))))
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -3,10 +3,21 @@ package utils
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"os/exec" "os/exec"
"time" "time"
) )
// FileExists ...
func FileExists(name string) bool {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
// CmdExists ... // CmdExists ...
func CmdExists(cmd string) bool { func CmdExists(cmd string) bool {
_, err := exec.LookPath(cmd) _, err := exec.LookPath(cmd)