Import song duration with hundredths when using TagLib
This is how ffmpeg extractor currently works, and it makes album durations more precise.
This commit is contained in:
@@ -32,7 +32,7 @@ var _ = Describe("Tags", func() {
|
|||||||
Expect(n).To(Equal(1))
|
Expect(n).To(Equal(1))
|
||||||
Expect(t).To(Equal(2))
|
Expect(t).To(Equal(2))
|
||||||
Expect(m.HasPicture()).To(BeTrue())
|
Expect(m.HasPicture()).To(BeTrue())
|
||||||
Expect(m.Duration()).To(BeNumerically("~", 1, 0.01))
|
Expect(m.Duration()).To(BeNumerically("~", 1.02, 0.01))
|
||||||
Expect(m.BitRate()).To(Equal(192))
|
Expect(m.BitRate()).To(Equal(192))
|
||||||
Expect(m.FilePath()).To(Equal("tests/fixtures/test.mp3"))
|
Expect(m.FilePath()).To(Equal("tests/fixtures/test.mp3"))
|
||||||
Expect(m.Suffix()).To(Equal("mp3"))
|
Expect(m.Suffix()).To(Equal("mp3"))
|
||||||
@@ -42,7 +42,7 @@ var _ = Describe("Tags", func() {
|
|||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
Expect(m.Title()).To(BeEmpty())
|
Expect(m.Title()).To(BeEmpty())
|
||||||
Expect(m.HasPicture()).To(BeFalse())
|
Expect(m.HasPicture()).To(BeFalse())
|
||||||
Expect(m.Duration()).To(BeNumerically("~", 1.00, 0.01))
|
Expect(m.Duration()).To(BeNumerically("~", 1.04, 0.01))
|
||||||
Expect(m.Suffix()).To(Equal("ogg"))
|
Expect(m.Suffix()).To(Equal("ogg"))
|
||||||
Expect(m.FilePath()).To(Equal("tests/fixtures/test.ogg"))
|
Expect(m.FilePath()).To(Equal("tests/fixtures/test.ogg"))
|
||||||
Expect(m.Size()).To(Equal(int64(5065)))
|
Expect(m.Size()).To(Equal(int64(5065)))
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package taglib
|
package taglib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/navidrome/navidrome/log"
|
"github.com/navidrome/navidrome/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,6 +34,13 @@ func (e *Parser) extractMetadata(filePath string) (parsedTags, error) {
|
|||||||
"tracknumber": {"trck", "_track"},
|
"tracknumber": {"trck", "_track"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if length, ok := tags["lengthinmilliseconds"]; ok && len(length) > 0 {
|
||||||
|
millis, _ := strconv.Atoi(length[0])
|
||||||
|
if duration := float64(millis) / 1000.0; duration > 0 {
|
||||||
|
tags["duration"] = []string{strconv.FormatFloat(duration, 'f', 2, 32)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for tagName, alternatives := range alternativeTags {
|
for tagName, alternatives := range alternativeTags {
|
||||||
for _, altName := range alternatives {
|
for _, altName := range alternatives {
|
||||||
if altValue, ok := tags[altName]; ok {
|
if altValue, ok := tags[altName]; ok {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ var _ = Describe("Parser", func() {
|
|||||||
Expect(m).To(HaveKeyWithValue("tracknumber", []string{"2/10", "2/10", "2"}))
|
Expect(m).To(HaveKeyWithValue("tracknumber", []string{"2/10", "2/10", "2"}))
|
||||||
Expect(m).To(HaveKeyWithValue("discnumber", []string{"1/2"}))
|
Expect(m).To(HaveKeyWithValue("discnumber", []string{"1/2"}))
|
||||||
Expect(m).To(HaveKeyWithValue("has_picture", []string{"true"}))
|
Expect(m).To(HaveKeyWithValue("has_picture", []string{"true"}))
|
||||||
Expect(m).To(HaveKeyWithValue("duration", []string{"1"}))
|
Expect(m).To(HaveKeyWithValue("duration", []string{"1.02"}))
|
||||||
Expect(m).To(HaveKeyWithValue("bitrate", []string{"192"}))
|
Expect(m).To(HaveKeyWithValue("bitrate", []string{"192"}))
|
||||||
Expect(m).To(HaveKeyWithValue("comment", []string{"Comment1\nComment2"}))
|
Expect(m).To(HaveKeyWithValue("comment", []string{"Comment1\nComment2"}))
|
||||||
Expect(m).To(HaveKeyWithValue("lyrics", []string{"Lyrics 1\rLyrics 2"}))
|
Expect(m).To(HaveKeyWithValue("lyrics", []string{"Lyrics 1\rLyrics 2"}))
|
||||||
@@ -37,7 +37,7 @@ var _ = Describe("Parser", func() {
|
|||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
Expect(m).ToNot(HaveKey("title"))
|
Expect(m).ToNot(HaveKey("title"))
|
||||||
Expect(m).ToNot(HaveKey("has_picture"))
|
Expect(m).ToNot(HaveKey("has_picture"))
|
||||||
Expect(m).To(HaveKeyWithValue("duration", []string{"1"}))
|
Expect(m).To(HaveKeyWithValue("duration", []string{"1.04"}))
|
||||||
Expect(m).To(HaveKeyWithValue("fbpm", []string{"141.7"}))
|
Expect(m).To(HaveKeyWithValue("fbpm", []string{"141.7"}))
|
||||||
|
|
||||||
// TabLib 1.12 returns 18, previous versions return 39.
|
// TabLib 1.12 returns 18, previous versions return 39.
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ int taglib_read(const char *filename, unsigned long id) {
|
|||||||
// Add audio properties to the tags
|
// Add audio properties to the tags
|
||||||
const TagLib::AudioProperties *props(f.audioProperties());
|
const TagLib::AudioProperties *props(f.audioProperties());
|
||||||
go_map_put_int(id, (char *)"duration", props->length());
|
go_map_put_int(id, (char *)"duration", props->length());
|
||||||
|
go_map_put_int(id, (char *)"lengthinmilliseconds", props->lengthInMilliseconds());
|
||||||
go_map_put_int(id, (char *)"bitrate", props->bitrate());
|
go_map_put_int(id, (char *)"bitrate", props->bitrate());
|
||||||
|
|
||||||
TagLib::PropertyMap tags = f.file()->properties();
|
TagLib::PropertyMap tags = f.file()->properties();
|
||||||
|
|||||||
Reference in New Issue
Block a user