Extract basic tags, as a fallback
This commit is contained in:
@@ -21,12 +21,37 @@ int taglib_read(const char *filename, unsigned long id) {
|
||||
return TAGLIB_ERR_AUDIO_PROPS;
|
||||
}
|
||||
|
||||
// Add audio properties to the tags
|
||||
const TagLib::AudioProperties *props(f.audioProperties());
|
||||
go_map_put_int(id, (char *)"length", props->length());
|
||||
go_map_put_int(id, (char *)"bitrate", props->bitrate());
|
||||
|
||||
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()));
|
||||
if (mp3File != NULL) {
|
||||
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();
|
||||
++i) {
|
||||
for (TagLib::StringList::ConstIterator j = i->second.begin();
|
||||
|
||||
@@ -38,7 +38,7 @@ func Read(filename string) (map[string]string, error) {
|
||||
if res != 0 {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user