From c0138ec10e28efd2a31e88ba94e991a8fb8145ae Mon Sep 17 00:00:00 2001 From: Heinrich 'Henrik' Langos Date: Wed, 4 Jan 2023 11:34:40 +0000 Subject: [PATCH] feat: Prefer external thumbnail over embedded ones (#44) This changes the handling of external thumbnails as mentioned in issue #41 If there is an external thumbnail file, it is going to be used, even if there is an embedded thumbnail in the mp4 file. Reviewed-on: https://git.mills.io/prologic/tube/pulls/44 Co-authored-by: Heinrich 'Henrik' Langos Co-committed-by: Heinrich 'Henrik' Langos --- media/video.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/media/video.go b/media/video.go index cc78973..fdd30f4 100644 --- a/media/video.go +++ b/media/video.go @@ -101,21 +101,22 @@ func ParseVideo(p *Path, name string) (*Video, error) { log.Println("Failed to read yml for", v.Path) } - // Add thumbnail (if exists) + // Add thumbnail from embedded tags (if exists) pic := m.Picture() if pic != nil { v.Thumb = pic.Data v.ThumbType = pic.MIMEType - } else { - thumbFn := fmt.Sprintf("%s.jpg", strings.TrimSuffix(pth, filepath.Ext(pth))) - if utils.FileExists(thumbFn) { - data, err := ioutil.ReadFile(fmt.Sprintf("%s.jpg", strings.TrimSuffix(pth, filepath.Ext(pth)))) - if err != nil { - return nil, err - } - v.Thumb = data - v.ThumbType = "image/jpeg" + } + + // Add thumbnail from external file (if exists) + if utils.FileExists(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 { + log.Println("Failed to read thumbnail file for", v.Path) + return nil, err } + v.Thumb = data + v.ThumbType = "image/jpeg" } return v, nil