Skip to content
Merged
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
5 changes: 3 additions & 2 deletions services/search/pkg/content/tika.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
return photo
}

func (t Tika) getAudio(meta map[string][]string) *libregraph.Audio {

Check failure on line 229 in services/search/pkg/content/tika.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=opencloud-eu_opencloud&issues=AZ2s6QFw7Za-YJMdNx1r&open=AZ2s6QFw7Za-YJMdNx1r&pullRequest=2638
var audio *libregraph.Audio
initAudio := func() {
if audio == nil {
Expand Down Expand Up @@ -264,9 +264,10 @@
// 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(math.Round(f * 1000)))
}
}

Expand Down
4 changes: 2 additions & 2 deletions services/search/pkg/content/tika_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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)))
Expand Down