Mercurial > hg > sonic-annotator
diff runner/JAMSFeatureWriter.cpp @ 166:e98b1abeb792 jams
Better track metadata
author | Chris Cannam |
---|---|
date | Wed, 15 Oct 2014 13:52:25 +0100 |
parents | d0be35a305cc |
children | e5873fb4ffb3 |
line wrap: on
line diff
--- a/runner/JAMSFeatureWriter.cpp Wed Oct 15 13:30:25 2014 +0100 +++ b/runner/JAMSFeatureWriter.cpp Wed Oct 15 13:52:25 2014 +0100 @@ -22,6 +22,8 @@ #include "base/Exceptions.h" #include "rdf/PluginRDFIndexer.h" +#include <QFileInfo> + #include "version.h" JAMSFeatureWriter::JAMSFeatureWriter() : @@ -75,12 +77,7 @@ void JAMSFeatureWriter::setTrackMetadata(QString trackId, TrackMetadata metadata) { - QString json - ("\n\"file_metadata\": {\n" - " \"artist\": \"%1\",\n" - " \"title\": \"%2\"\n},\n"); - m_metadata[trackId] = json.arg(metadata.maker).arg(metadata.title); - cerr << "setTrackMetadata: metadata is: " << m_metadata[trackId] << endl; + m_metadata[trackId] = metadata; } static double @@ -110,7 +107,24 @@ if (m_startedTargets.find(targetKey) == m_startedTargets.end()) { // Need to write track-level preamble - stream << "{" << m_metadata[trackId] << endl; + stream << "{\n"; + stream << QString("\"file_metadata\": {\n" + " \"filename\": \"%1\"") + .arg(QFileInfo(trackId).fileName()); + + if (m_metadata.find(trackId) != m_metadata.end()) { + if (m_metadata[trackId].maker != "") { + stream << QString(",\n \"artist\": \"%1\"") + .arg(m_metadata[trackId].maker); + } + if (m_metadata[trackId].title != "") { + stream << QString(",\n \"title\": \"%1\"") + .arg(m_metadata[trackId].title); + } + } + + stream << "\n},\n"; + m_startedTargets.insert(targetKey); }