Don't generate new thumbnails if they already exist
This commit is contained in:
parent
7492a150eb
commit
8ae65e4b73
2 changed files with 18 additions and 4 deletions
|
@ -79,11 +79,14 @@ func ParseVideo(p *Path, name string) (*Video, error) {
|
|||
v.Thumb = pic.Data
|
||||
v.ThumbType = pic.MIMEType
|
||||
} 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 {
|
||||
err := fmt.Errorf("error generating thumbnail: %w", err)
|
||||
log.Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
data, err := ioutil.ReadFile(fmt.Sprintf("%s.jpg", strings.TrimSuffix(pth, filepath.Ext(pth))))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -3,10 +3,21 @@ package utils
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FileExists ...
|
||||
func FileExists(name string) bool {
|
||||
if _, err := os.Stat(name); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// CmdExists ...
|
||||
func CmdExists(cmd string) bool {
|
||||
_, err := exec.LookPath(cmd)
|
||||
|
|
Loading…
Reference in a new issue