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 <gumbo2000@noreply@mills.io>
Co-committed-by: Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io>
This commit is contained in:
Heinrich 'Henrik' Langos 2023-01-04 11:34:40 +00:00 committed by James Mills
parent 0a793f7d3f
commit c0138ec10e

View file

@ -101,22 +101,23 @@ func ParseVideo(p *Path, name string) (*Video, error) {
log.Println("Failed to read yml for", v.Path) log.Println("Failed to read yml for", v.Path)
} }
// Add thumbnail (if exists) // Add thumbnail from embedded tags (if exists)
pic := m.Picture() pic := m.Picture()
if pic != nil { if pic != nil {
v.Thumb = pic.Data v.Thumb = pic.Data
v.ThumbType = pic.MIMEType v.ThumbType = pic.MIMEType
} else { }
thumbFn := fmt.Sprintf("%s.jpg", strings.TrimSuffix(pth, filepath.Ext(pth)))
if utils.FileExists(thumbFn) { // 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)))) data, err := ioutil.ReadFile(fmt.Sprintf("%s.jpg", strings.TrimSuffix(pth, filepath.Ext(pth))))
if err != nil { if err != nil {
log.Println("Failed to read thumbnail file for", v.Path)
return nil, err return nil, err
} }
v.Thumb = data v.Thumb = data
v.ThumbType = "image/jpeg" v.ThumbType = "image/jpeg"
} }
}
return v, nil return v, nil
} }