diff --git a/media/video.go b/media/video.go index f37c697..e864be0 100644 --- a/media/video.go +++ b/media/video.go @@ -79,10 +79,13 @@ func ParseVideo(p *Path, name string) (*Video, error) { v.Thumb = pic.Data v.ThumbType = pic.MIMEType } else if utils.CmdExists("mt") { - 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 + 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 { diff --git a/utils/utils.go b/utils/utils.go index 0ca1cea..b7ab28f 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -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)