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,10 +79,13 @@ 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") {
|
||||||
if err := utils.RunCmd(10, "mt", "-s", "-n", "1", pth); err != nil {
|
thumbFn := fmt.Sprintf("%s.jpg", strings.TrimSuffix(pth, filepath.Ext(pth)))
|
||||||
err := fmt.Errorf("error generating thumbnail: %w", err)
|
if !utils.FileExists(thumbFn) {
|
||||||
log.Error(err.Error())
|
if err := utils.RunCmd(10, "mt", "-s", "-n", "1", pth); err != nil {
|
||||||
return nil, err
|
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))))
|
data, err := ioutil.ReadFile(fmt.Sprintf("%s.jpg", strings.TrimSuffix(pth, filepath.Ext(pth))))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue