feat(scanner): use wrtag/coverparse for cover selection

later, gonic will also use wrtag/tags for tag parsing

closes #338
closes #516
This commit is contained in:
sentriz
2024-09-12 18:32:36 +01:00
parent 120fd7959a
commit 453639ee34
3 changed files with 8 additions and 24 deletions

View File

@@ -25,6 +25,7 @@ import (
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/fileutil"
"go.senan.xyz/gonic/tags/tagcommon"
"go.senan.xyz/wrtag/coverparse"
)
var (
@@ -277,8 +278,8 @@ func (s *Scanner) scanDir(tx *db.DB, st *State, absPath string) error {
continue
}
if isCover(item.Name()) {
cover = item.Name()
if coverparse.IsCover(item.Name()) {
coverparse.BestBetween(&cover, item.Name())
continue
}
if s.tagReader.CanRead(absPath) {
@@ -671,26 +672,6 @@ func (s *Scanner) cleanGenres(st *State) error { //nolint:unparam
return nil
}
//nolint:gochecknoglobals
var coverNames = map[string]struct{}{}
//nolint:gochecknoinits
func init() {
for _, name := range []string{"cover", "folder", "front", "albumart", "album", "artist"} {
for _, ext := range []string{"jpg", "jpeg", "png", "bmp", "gif"} {
coverNames[fmt.Sprintf("%s.%s", name, ext)] = struct{}{}
for i := 0; i < 3; i++ {
coverNames[fmt.Sprintf("%s.%d.%s", name, i, ext)] = struct{}{} // support beets extras
}
}
}
}
func isCover(name string) bool {
_, ok := coverNames[strings.ToLower(name)]
return ok
}
// decoded converts a string to it's latin equivalent.
// it will be used by the model's *UDec fields, and is only set if it
// differs from the original. the fields are used for searching.