Use TagLib to detect whether a media file has embedded cover or not
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package metadata
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/dhowden/tag"
|
||||
"github.com/navidrome/navidrome/log"
|
||||
"github.com/navidrome/navidrome/scanner/metadata/taglib"
|
||||
)
|
||||
@@ -25,10 +22,6 @@ func (e *taglibExtractor) extractMetadata(filePath string) (*Tags, error) {
|
||||
parsedTags, err := taglib.Read(filePath)
|
||||
if err != nil {
|
||||
log.Warn("Error reading metadata from file. Skipping", "filePath", filePath, err)
|
||||
} else {
|
||||
if hasEmbeddedImage(filePath) {
|
||||
parsedTags["has_picture"] = []string{"true"}
|
||||
}
|
||||
}
|
||||
|
||||
tags := NewTags(filePath, parsedTags, map[string][]string{
|
||||
@@ -41,25 +34,3 @@ func (e *taglibExtractor) extractMetadata(filePath string) (*Tags, error) {
|
||||
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func hasEmbeddedImage(path string) bool {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Error("Panic while checking for images. Please report this error with a copy of the file", "path", path, r)
|
||||
}
|
||||
}()
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Warn("Error opening file", "filePath", path, err)
|
||||
return false
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
m, err := tag.ReadFrom(f)
|
||||
if err != nil {
|
||||
log.Warn("Error reading picture tag from file", "filePath", path, err)
|
||||
return false
|
||||
}
|
||||
|
||||
return m.Picture() != nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user