mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-21 08:47:16 +02:00
* fix(scanner): keep tag numbers within the int32 range A track number of 4294967295 (-1 stored as an unsigned 32-bit tag) was saved as-is by 64-bit builds. 32-bit builds (armv5/6/7, 386) cannot read that value back into an int, so every scan failed with "converting driver.Value type int64 to a int: value out of range" when loading the folder's media files. Track and disc numbers (and their totals) are now parsed as int32 and fall back to 0 when out of range, matching how unparseable values are handled. BPM values outside the int32 range are dropped. A migration resets existing out-of-range track_number, disc_number and bpm values, and removes out-of-range keys from album.discs, so databases written by 64-bit builds are readable again by 32-bit ones. Persistent IDs are unaffected because they use the raw tag text. Fixes #6200 * fix(scanner): accept the int32 minimum as a BPM value The BPM range check compared the absolute value against MaxInt32, which rejected -2147483648 even though it fits in an int32. Compare against MinInt32 and MaxInt32 separately, matching atoi32 and the migration. * fix(scanner): treat negative track, disc and BPM values as missing Track numbers, disc numbers and BPM can never be negative, so negative tag values now map to 0 (track/disc, including totals) or nil (BPM), the same as unparseable ones. The migration resets existing negative values as well as the ones above the int32 range, and keeps only album disc keys from 0 to MaxInt32.
157 lines
5 KiB
Go
157 lines
5 KiB
Go
package metadata_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"sort"
|
|
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/navidrome/navidrome/model/metadata"
|
|
"github.com/navidrome/navidrome/tests"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("ToMediaFile", func() {
|
|
var (
|
|
props metadata.Info
|
|
md metadata.Metadata
|
|
mf model.MediaFile
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
_, filePath, _ := tests.TempFile(GinkgoT(), "test", ".mp3")
|
|
fileInfo, _ := os.Stat(filePath)
|
|
props = metadata.Info{
|
|
FileInfo: testFileInfo{fileInfo},
|
|
}
|
|
})
|
|
|
|
var toMediaFile = func(tags model.RawTags) model.MediaFile {
|
|
props.Tags = tags
|
|
md = metadata.New("filepath", props)
|
|
return md.ToMediaFile(1, "folderID")
|
|
}
|
|
|
|
Describe("Dates", func() {
|
|
It("should parse properly tagged dates ", func() {
|
|
mf = toMediaFile(model.RawTags{
|
|
"ORIGINALDATE": {"1978-09-10"},
|
|
"DATE": {"1977-03-04"},
|
|
"RELEASEDATE": {"2002-01-02"},
|
|
})
|
|
|
|
Expect(mf.Year).To(Equal(1977))
|
|
Expect(mf.Date).To(Equal("1977-03-04"))
|
|
Expect(mf.OriginalYear).To(Equal(1978))
|
|
Expect(mf.OriginalDate).To(Equal("1978-09-10"))
|
|
Expect(mf.ReleaseYear).To(Equal(2002))
|
|
Expect(mf.ReleaseDate).To(Equal("2002-01-02"))
|
|
})
|
|
|
|
It("should parse dates with only year", func() {
|
|
mf = toMediaFile(model.RawTags{
|
|
"ORIGINALYEAR": {"1978"},
|
|
"DATE": {"1977"},
|
|
"RELEASEDATE": {"2002"},
|
|
})
|
|
|
|
Expect(mf.Year).To(Equal(1977))
|
|
Expect(mf.Date).To(Equal("1977"))
|
|
Expect(mf.OriginalYear).To(Equal(1978))
|
|
Expect(mf.OriginalDate).To(Equal("1978"))
|
|
Expect(mf.ReleaseYear).To(Equal(2002))
|
|
Expect(mf.ReleaseDate).To(Equal("2002"))
|
|
})
|
|
|
|
It("should parse dates tagged the legacy way (no release date)", func() {
|
|
mf = toMediaFile(model.RawTags{
|
|
"DATE": {"2014"},
|
|
"ORIGINALDATE": {"1966"},
|
|
})
|
|
|
|
Expect(mf.Year).To(Equal(1966))
|
|
Expect(mf.OriginalYear).To(Equal(1966))
|
|
Expect(mf.ReleaseYear).To(Equal(2014))
|
|
})
|
|
DescribeTable("legacyReleaseDate (TaggedLikePicard old behavior)",
|
|
func(recordingDate, originalDate, releaseDate, expected string) {
|
|
mf := toMediaFile(model.RawTags{
|
|
"DATE": {recordingDate},
|
|
"ORIGINALDATE": {originalDate},
|
|
"RELEASEDATE": {releaseDate},
|
|
})
|
|
|
|
Expect(mf.ReleaseDate).To(Equal(expected))
|
|
},
|
|
Entry("regular mapping", "2020-05-15", "2019-02-10", "2021-01-01", "2021-01-01"),
|
|
Entry("legacy mapping", "2020-05-15", "2019-02-10", "", "2020-05-15"),
|
|
Entry("legacy mapping, originalYear < year", "2018-05-15", "2019-02-10", "2021-01-01", "2021-01-01"),
|
|
Entry("legacy mapping, originalYear empty", "2020-05-15", "", "2021-01-01", "2021-01-01"),
|
|
Entry("legacy mapping, releaseYear", "2020-05-15", "2019-02-10", "2021-01-01", "2021-01-01"),
|
|
Entry("legacy mapping, same dates", "2020-05-15", "2020-05-15", "", "2020-05-15"),
|
|
)
|
|
})
|
|
|
|
Describe("Lyrics", func() {
|
|
It("should parse the lyrics", func() {
|
|
mf = toMediaFile(model.RawTags{
|
|
"LYRICS:XXX": {"Lyrics"},
|
|
"LYRICS:ENG": {
|
|
"[00:00.00]This is\n[00:02.50]English SYLT\n",
|
|
},
|
|
})
|
|
var actual model.LyricList
|
|
err := json.Unmarshal([]byte(mf.Lyrics), &actual)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
expected := model.LyricList{
|
|
{Lang: "eng", Line: []model.Line{
|
|
{Value: "This is", Start: new(int64(0))},
|
|
{Value: "English SYLT", Start: new(int64(2500))},
|
|
}, Synced: true},
|
|
{Lang: "xxx", Line: []model.Line{{Value: "Lyrics"}}, Synced: false},
|
|
}
|
|
sort.Slice(actual, func(i, j int) bool { return actual[i].Lang < actual[j].Lang })
|
|
sort.Slice(expected, func(i, j int) bool { return expected[i].Lang < expected[j].Lang })
|
|
Expect(actual).To(Equal(expected))
|
|
})
|
|
})
|
|
|
|
Describe("BPM", func() {
|
|
It("maps the BPM tag rounded to the nearest integer", func() {
|
|
mf = toMediaFile(model.RawTags{"BPM": {"120.6"}})
|
|
Expect(mf.BPM).To(Equal(new(121)))
|
|
})
|
|
It("leaves BPM nil when the tag is absent", func() {
|
|
mf = toMediaFile(model.RawTags{})
|
|
Expect(mf.BPM).To(BeNil())
|
|
})
|
|
It("leaves BPM nil when the tag is zero or unparseable", func() {
|
|
Expect(toMediaFile(model.RawTags{"BPM": {"0"}}).BPM).To(BeNil())
|
|
Expect(toMediaFile(model.RawTags{"BPM": {"fast"}}).BPM).To(BeNil())
|
|
})
|
|
It("leaves BPM nil when the tag does not fit in 32 bits", func() {
|
|
Expect(toMediaFile(model.RawTags{"BPM": {"4294967295"}}).BPM).To(BeNil())
|
|
})
|
|
It("leaves BPM nil when the tag is negative", func() {
|
|
Expect(toMediaFile(model.RawTags{"BPM": {"-120"}}).BPM).To(BeNil())
|
|
})
|
|
It("keeps the largest 32-bit BPM value", func() {
|
|
Expect(toMediaFile(model.RawTags{"BPM": {"2147483647"}}).BPM).To(Equal(new(2147483647)))
|
|
})
|
|
})
|
|
|
|
Describe("BitDepth", func() {
|
|
It("maps the bit depth when present", func() {
|
|
props.AudioProperties = metadata.AudioProperties{BitDepth: 24}
|
|
mf = toMediaFile(model.RawTags{})
|
|
Expect(mf.BitDepth).To(Equal(new(24)))
|
|
})
|
|
It("leaves BitDepth nil when zero (lossy codecs have no bit depth)", func() {
|
|
props.AudioProperties = metadata.AudioProperties{BitDepth: 0}
|
|
mf = toMediaFile(model.RawTags{})
|
|
Expect(mf.BitDepth).To(BeNil())
|
|
})
|
|
})
|
|
})
|