Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions adapters/gotaglib/gotaglib.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/core/storage/local"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/model/metadata"
"go.senan.xyz/taglib"
)
Expand All @@ -36,6 +37,29 @@ func (e extractor) Parse(files ...string) (map[string]metadata.Info, error) {
for _, path := range files {
props, err := e.extractMetadata(path)
if err != nil {
if !conf.Server.Scanner.ImportOnReadError {
continue
}
log.Warn("gotaglib: Error reading metadata from file. Importing without metadata", "filePath", path, err)
f, openErr := e.fs.Open(path)
if openErr != nil {
continue
}
info, statErr := f.Stat()
_ = f.Close()
if statErr != nil {
continue
}
fileInfo, ok := info.(metadata.FileInfo)
if !ok {
continue
}
results[path] = metadata.Info{
FileInfo: fileInfo,
Tags: model.RawTags{},
AudioProperties: metadata.AudioProperties{},
HasPicture: false,
}
continue
}
results[path] = *props
Expand Down
42 changes: 42 additions & 0 deletions adapters/gotaglib/gotaglib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

"github.com/navidrome/navidrome/tests"
"github.com/navidrome/navidrome/utils"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/model/metadata"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -252,6 +254,46 @@
})
})

Context("when metadata cannot be read", func() {
var invalidFile string

BeforeEach(func() {
invalidFile = utils.TempFileName("invalid-audio-", ".xm")

Expect(os.WriteFile(invalidFile, []byte("this is not a valid audio file"), 0644)).To(Succeed())

Check failure on line 263 in adapters/gotaglib/gotaglib_test.go

View workflow job for this annotation

GitHub Actions / Lint Go code

G306: Expect WriteFile permissions to be 0600 or less (gosec)

DeferCleanup(func() {
Expect(os.Remove(invalidFile)).To(Succeed())
})

// Use root fs for absolute paths in temp directory
e = &extractor{fs: os.DirFS("/")}
})

It("skips the file when ImportOnReadError is disabled", func() {
conf.Server.Scanner.ImportOnReadError = false

// Strip leading slash for DirFS rooted at "/"
mds, err := e.Parse(invalidFile[1:])
Expect(err).ToNot(HaveOccurred())
Expect(mds).ToNot(HaveKey(invalidFile[1:]))
})

It("imports the file with empty metadata when ImportOnReadError is enabled", func() {
conf.Server.Scanner.ImportOnReadError = true

// Strip leading slash for DirFS rooted at "/"
mds, err := e.Parse(invalidFile[1:])
Expect(err).ToNot(HaveOccurred())
Expect(mds).To(HaveKey(invalidFile[1:]))

m := mds[invalidFile[1:]]
Expect(m.Tags).To(BeEmpty())
Expect(m.HasPicture).To(BeFalse())
Expect(m.AudioProperties).To(Equal(metadata.AudioProperties{}))
})
})

})

Describe("Error Checking", func() {
Expand Down
2 changes: 2 additions & 0 deletions conf/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ type scannerOptions struct {
GroupAlbumReleases bool // Deprecated: Use PID.Album instead
FollowSymlinks bool // Whether to follow symlinks when scanning directories
PurgeMissing string // Values: "never", "always", "full"
ImportOnReadError bool
}

type subsonicOptions struct {
Expand Down Expand Up @@ -815,6 +816,7 @@ func setViperDefaults() {
viper.SetDefault("scanner.groupalbumreleases", false)
viper.SetDefault("scanner.followsymlinks", true)
viper.SetDefault("scanner.purgemissing", consts.PurgeMissingNever)
viper.SetDefault("scanner.importonreaderror", false)
viper.SetDefault("subsonic.appendsubtitle", true)
viper.SetDefault("subsonic.appendalbumversion", true)
viper.SetDefault("subsonic.artistparticipations", false)
Expand Down
Loading