mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-01 12:43:08 -04:00
fix(search): parse tika xmpDM:duration as a float
Tika emits xmpDM:duration as seconds in floating-point form (for example "154.57379150390625"), so strconv.ParseInt rejected every value and the field was silently dropped — every indexed audio item ended up without a duration. Parse the value with strconv.ParseFloat and convert to milliseconds ourselves. Adjust the existing extractor test to cover the fractional case.
This commit is contained in:
committed by
Ralf Haferkamp
parent
7212f06c41
commit
3c59935012
@@ -264,9 +264,10 @@ func (t Tika) getAudio(meta map[string][]string) *libregraph.Audio {
|
||||
// TODO: audio.DiscCount: not provided by tika
|
||||
|
||||
if v, err := getFirstValue(meta, "xmpDM:duration"); err == nil {
|
||||
if i, err := strconv.ParseInt(v, 10, 64); err == nil {
|
||||
// Tika emits fractional seconds.
|
||||
if f, err := strconv.ParseFloat(v, 64); err == nil {
|
||||
initAudio()
|
||||
audio.SetDuration(i * 1000)
|
||||
audio.SetDuration(int64(f * 1000))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ var _ = Describe("Tika", func() {
|
||||
"xmpDM:audioSampleRate": "44100",
|
||||
"channels": "2",
|
||||
"dc:title": "Some Title",
|
||||
"xmpDM:duration": "225",
|
||||
"xmpDM:duration": "225.5",
|
||||
"Content-Type": "audio/mpeg",
|
||||
"samplerate": "44100"
|
||||
}
|
||||
@@ -130,7 +130,7 @@ var _ = Describe("Tika", func() {
|
||||
// Expect(audio.Copyright).To(Equal(libregraph.PtrString("Some Copyright")))
|
||||
Expect(audio.Disc).To(Equal(libregraph.PtrInt32(4)))
|
||||
// Expect(audio.DiscCount).To(Equal(libregraph.PtrInt32(5)))
|
||||
Expect(audio.Duration).To(Equal(libregraph.PtrInt64(225000)))
|
||||
Expect(audio.Duration).To(Equal(libregraph.PtrInt64(225500)))
|
||||
Expect(audio.Genre).To(Equal(libregraph.PtrString("Some Genre")))
|
||||
// Expect(audio.HasDrm).To(Equal(libregraph.PtrBool(false)))
|
||||
// Expect(audio.IsVariableBitrate).To(Equal(libregraph.PtrBool(true)))
|
||||
|
||||
Reference in New Issue
Block a user