diff --git a/mockfs/mockfs.go b/mockfs/mockfs.go index 0b36645..42505dc 100644 --- a/mockfs/mockfs.go +++ b/mockfs/mockfs.go @@ -339,6 +339,10 @@ func (m *tagReader) Read(absPath string) (tags.Properties, map[string][]string, return props, p.Tags, nil } +func (m *tagReader) ReadCover(absPath string) ([]byte, error) { + return nil, nil +} + type TagInfo struct { Tags map[string][]string Length time.Duration diff --git a/tags/ffprobe/ffprobe.go b/tags/ffprobe/ffprobe.go index b0a7c65..3b289f9 100644 --- a/tags/ffprobe/ffprobe.go +++ b/tags/ffprobe/ffprobe.go @@ -60,3 +60,11 @@ func (Reader) Read(absPath string) (tags.Properties, map[string][]string, error) return props, tgs, nil } + +func (Reader) ReadCover(absPath string) ([]byte, error) { + out, err := exec.Command("ffmpeg", "-i", absPath, "-map", "0:v", "-c", "copy", "-f", "image2pipe", "-").Output() + if err != nil { + return nil, fmt.Errorf("exec: %w", err) + } + return out, nil +} diff --git a/tags/taglib/taglib.go b/tags/taglib/taglib.go index 4a6bfbe..0709fe0 100644 --- a/tags/taglib/taglib.go +++ b/tags/taglib/taglib.go @@ -34,3 +34,7 @@ func (Reader) Read(absPath string) (tags.Properties, map[string][]string, error) return tags.Properties{Length: tp.Length, Bitrate: tp.Bitrate}, tag, nil } + +func (Reader) ReadCover(absPath string) ([]byte, error) { + return taglib.ReadImage(absPath) +} diff --git a/tags/tags.go b/tags/tags.go index 6a7fde9..af3bf92 100644 --- a/tags/tags.go +++ b/tags/tags.go @@ -16,6 +16,7 @@ var ErrUnsupported = errors.New("filetype unsupported") type Reader interface { CanRead(absPath string) bool Read(absPath string) (properties Properties, tags map[string][]string, err error) + ReadCover(absPath string) ([]byte, error) } type Properties struct {