Manually add replaygain tags for m4a (#2346)
* manually add replaygain tags for m4a * Add replaygain tests for m4a, mp4, ogg * add new valye for bitrate
This commit is contained in:
@@ -65,7 +65,35 @@ var _ = Describe("Extractor", func() {
|
||||
// TabLib 1.12 returns 18, previous versions return 39.
|
||||
// See https://github.com/taglib/taglib/commit/2f238921824741b2cfe6fbfbfc9701d9827ab06b
|
||||
Expect(m).To(HaveKey("bitrate"))
|
||||
Expect(m["bitrate"][0]).To(BeElementOf("18", "39"))
|
||||
Expect(m["bitrate"][0]).To(BeElementOf("18", "39", "40"))
|
||||
})
|
||||
|
||||
Context("ReplayGain", func() {
|
||||
testGain := func(file, albumGain, albumPeak, trackGain, trackPeak string) {
|
||||
file = "tests/fixtures/" + file
|
||||
mds, err := e.Parse(file)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(mds).To(HaveLen(1))
|
||||
|
||||
m := mds[file]
|
||||
|
||||
Expect(m).To(HaveKeyWithValue("replaygain_album_gain", []string{albumGain}))
|
||||
Expect(m).To(HaveKeyWithValue("replaygain_album_peak", []string{albumPeak}))
|
||||
Expect(m).To(HaveKeyWithValue("replaygain_track_gain", []string{trackGain}))
|
||||
Expect(m).To(HaveKeyWithValue("replaygain_track_peak", []string{trackPeak}))
|
||||
}
|
||||
|
||||
It("Correctly parses m4a (aac) gain tags", func() {
|
||||
testGain("01 Invisible (RED) Edit Version.m4a", "0.37", "0.48", "0.37", "0.48")
|
||||
})
|
||||
|
||||
It("correctly parses mp3 tags", func() {
|
||||
testGain("test.mp3", "+3.21518 dB", "0.9125", "-1.48 dB", "0.4512")
|
||||
})
|
||||
|
||||
It("correctly parses ogg (vorbis) tags", func() {
|
||||
testGain("test.ogg", "+7.64 dB", "0.11772506", "+7.64 dB", "0.11772506")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
|
||||
#include "taglib_wrapper.h"
|
||||
|
||||
// Tags necessary for M4a parsing
|
||||
const char *RG_TAGS[] = {
|
||||
"replaygain_album_gain",
|
||||
"replaygain_album_peak",
|
||||
"replaygain_track_gain",
|
||||
"replaygain_track_peak"};
|
||||
|
||||
char has_cover(const TagLib::FileRef f);
|
||||
|
||||
int taglib_read(const FILENAME_CHAR_T *filename, unsigned long id) {
|
||||
@@ -70,6 +77,29 @@ int taglib_read(const FILENAME_CHAR_T *filename, unsigned long id) {
|
||||
}
|
||||
}
|
||||
|
||||
TagLib::MP4::File *m4afile(dynamic_cast<TagLib::MP4::File *>(f.file()));
|
||||
if (m4afile != NULL)
|
||||
{
|
||||
const auto itemListMap = m4afile->tag();
|
||||
{
|
||||
char buf[200];
|
||||
|
||||
for (const char *key : RG_TAGS)
|
||||
{
|
||||
snprintf(buf, sizeof(buf), "----:com.apple.iTunes:%s", key);
|
||||
const auto item = itemListMap->item(buf);
|
||||
if (item.isValid())
|
||||
{
|
||||
char *dup = ::strdup(key);
|
||||
char *val = ::strdup(item.toStringList().front().toCString(true));
|
||||
go_map_put_str(id, dup, val);
|
||||
free(dup);
|
||||
free(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (has_cover(f)) {
|
||||
go_map_put_str(id, (char *)"has_picture", (char *)"true");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user