🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Check MIME type for cover on refresh, display
Alex Palaistrasac5d99c079af
diff --git a/engine/cover.go b/engine/cover.goindex 7aa2363a0..df054ae83 100644--- a/engine/cover.go+++ b/engine/cover.go@@ -10,6 +10,7 @@ import ("image/jpeg"_ "image/png""io"+ "mime""os""path/filepath""strings"@@ -134,18 +135,16 @@ func (c *cover) getCover(ctx context.Context, path string, size int) (reader io.reader, err = resources.AssetFile().Open(consts.PlaceholderAlbumArt)}}()++ if path == "" {+ return nil, errors.New("empty path given for cover")+ }+var data []byte- err = errors.New("no matching cover found")- for _, p := range strings.Split(conf.Server.CoverArtPriority, ",") {- pat := strings.ToLower(strings.TrimSpace(p))- if pat == "embedded" {- data, err = readFromTag(path)- } else if ok, _ := filepath.Match(pat, strings.ToLower(filepath.Base(path))); ok {- data, err = readFromFile(path)- }- if err == nil {- break- }+ if isAudioFile(filepath.Ext(path)) {+ data, err = readFromTag(path)+ } else {+ data, err = readFromFile(path)}if err != nil {@@ -208,6 +207,10 @@ func readFromFile(path string) ([]byte, error) {return buf.Bytes(), nil}+func isAudioFile(extension string) bool {+ return strings.HasPrefix(mime.TypeByExtension(extension), "audio/")+}+func NewImageCache() (ImageCache, error) {return newFileCache("Image", conf.Server.ImageCacheSize, consts.ImageCacheDir, consts.DefaultImageCacheMaxItems)}diff --git a/persistence/album_repository.go b/persistence/album_repository.goindex 2776e5e7c..0ef49c6cd 100644--- a/persistence/album_repository.go+++ b/persistence/album_repository.go@@ -2,6 +2,7 @@ package persistenceimport ("context"+ "mime""os""path/filepath""sort"@@ -220,7 +221,8 @@ func getCoverFromPath(path string, hasEmbeddedCover bool) string {}for _, name := range names {- if ok, _ := filepath.Match(pat, strings.ToLower(name)); ok {+ match, _ := filepath.Match(pat, strings.ToLower(name))+ if match && isImageFile(filepath.Ext(name)) {return filepath.Join(filepath.Dir(path), name)}}@@ -229,6 +231,10 @@ func getCoverFromPath(path string, hasEmbeddedCover bool) string {return ""}+func isImageFile(extension string) bool {+ return strings.HasPrefix(mime.TypeByExtension(extension), "image/")+}+func (r *albumRepository) purgeEmpty() error {del := Delete(r.tableName).Where("id not in (select distinct(album_id) from media_file)")c, err := r.executeSQL(del)