Extract basic tags, as a fallback
This commit is contained in:
@@ -115,15 +115,17 @@ func (m *baseMetadata) parseFloat(tagName string) float32 {
|
|||||||
|
|
||||||
var dateRegex = regexp.MustCompile(`([12]\d\d\d)`)
|
var dateRegex = regexp.MustCompile(`([12]\d\d\d)`)
|
||||||
|
|
||||||
func (m *baseMetadata) parseYear(tagName string) int {
|
func (m *baseMetadata) parseYear(tags ...string) int {
|
||||||
if v, ok := m.tags[tagName]; ok {
|
for _, t := range tags {
|
||||||
match := dateRegex.FindStringSubmatch(v)
|
if v, ok := m.tags[t]; ok {
|
||||||
if len(match) == 0 {
|
match := dateRegex.FindStringSubmatch(v)
|
||||||
log.Warn("Error parsing year from ffmpeg date field", "file", m.filePath, "date", v)
|
if len(match) == 0 {
|
||||||
return 0
|
log.Warn("Error parsing year from ffmpeg date field", "file", m.filePath, "date", v)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
year, _ := strconv.Atoi(match[1])
|
||||||
|
return year
|
||||||
}
|
}
|
||||||
year, _ := strconv.Atoi(match[1])
|
|
||||||
return year
|
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,14 @@ type taglibMetadata struct {
|
|||||||
hasPicture bool
|
hasPicture bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *taglibMetadata) Title() string { return m.getTag("title", "titlesort", "_track") }
|
||||||
|
func (m *taglibMetadata) Album() string { return m.getTag("album", "albumsort", "_album") }
|
||||||
|
func (m *taglibMetadata) Artist() string { return m.getTag("artist", "artistsort", "_artist") }
|
||||||
|
func (m *taglibMetadata) Genre() string { return m.getTag("genre", "_genre") }
|
||||||
|
func (m *taglibMetadata) Year() int { return m.parseYear("date", "_year") }
|
||||||
|
func (m *taglibMetadata) TrackNumber() (int, int) {
|
||||||
|
return m.parseTuple("track", "tracknumber", "_track")
|
||||||
|
}
|
||||||
func (m *taglibMetadata) Duration() float32 { return m.parseFloat("length") }
|
func (m *taglibMetadata) Duration() float32 { return m.parseFloat("length") }
|
||||||
func (m *taglibMetadata) BitRate() int { return m.parseInt("bitrate") }
|
func (m *taglibMetadata) BitRate() int { return m.parseInt("bitrate") }
|
||||||
func (m *taglibMetadata) HasPicture() bool { return m.hasPicture }
|
func (m *taglibMetadata) HasPicture() bool { return m.hasPicture }
|
||||||
|
|||||||
@@ -21,12 +21,37 @@ int taglib_read(const char *filename, unsigned long id) {
|
|||||||
return TAGLIB_ERR_AUDIO_PROPS;
|
return TAGLIB_ERR_AUDIO_PROPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add audio properties to the tags
|
||||||
const TagLib::AudioProperties *props(f.audioProperties());
|
const TagLib::AudioProperties *props(f.audioProperties());
|
||||||
go_map_put_int(id, (char *)"length", props->length());
|
go_map_put_int(id, (char *)"length", props->length());
|
||||||
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();
|
||||||
|
|
||||||
|
// Make sure at least the basic properties are extracted
|
||||||
|
TagLib::Tag *basic = f.file()->tag();
|
||||||
|
if (!basic->isEmpty()) {
|
||||||
|
if (!basic->title().isEmpty()) {
|
||||||
|
tags.insert("_title", basic->title());
|
||||||
|
}
|
||||||
|
if (!basic->artist().isEmpty()) {
|
||||||
|
tags.insert("_artist", basic->artist());
|
||||||
|
}
|
||||||
|
if (!basic->album().isEmpty()) {
|
||||||
|
tags.insert("_album", basic->album());
|
||||||
|
}
|
||||||
|
if (!basic->genre().isEmpty()) {
|
||||||
|
tags.insert("_genre", basic->genre());
|
||||||
|
}
|
||||||
|
if (basic->year() > 0) {
|
||||||
|
tags.insert("_year", TagLib::String::number(basic->year()));
|
||||||
|
}
|
||||||
|
if (basic->track() > 0) {
|
||||||
|
tags.insert("_track", TagLib::String::number(basic->track()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get some extended/non-standard ID3-only tags (ex: iTunes extended frames)
|
||||||
TagLib::MPEG::File *mp3File(dynamic_cast<TagLib::MPEG::File *>(f.file()));
|
TagLib::MPEG::File *mp3File(dynamic_cast<TagLib::MPEG::File *>(f.file()));
|
||||||
if (mp3File != NULL) {
|
if (mp3File != NULL) {
|
||||||
if (mp3File->ID3v2Tag()) {
|
if (mp3File->ID3v2Tag()) {
|
||||||
@@ -39,6 +64,7 @@ int taglib_read(const char *filename, unsigned long id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get only the first occurrence of each tag (for now)
|
||||||
for (TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end();
|
for (TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end();
|
||||||
++i) {
|
++i) {
|
||||||
for (TagLib::StringList::ConstIterator j = i->second.begin();
|
for (TagLib::StringList::ConstIterator j = i->second.begin();
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func Read(filename string) (map[string]string, error) {
|
|||||||
if res != 0 {
|
if res != 0 {
|
||||||
return nil, fmt.Errorf("cannot process %s", filename)
|
return nil, fmt.Errorf("cannot process %s", filename)
|
||||||
}
|
}
|
||||||
log.Trace("TagLib: read tags", "tags", m, "filename", "filename")
|
log.Debug("TagLib: read tags", "tags", m, "filename", filename)
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user