# HG changeset patch # User Chris Cannam # Date 1413377545 -3600 # Node ID e98b1abeb792342b0067b2561314c74440871cec # Parent d0be35a305cc3848745e5fa13c18fb2d48d125c0 Better track metadata diff -r d0be35a305cc -r e98b1abeb792 runner/JAMSFeatureWriter.cpp --- 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 + #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); } diff -r d0be35a305cc -r e98b1abeb792 runner/JAMSFeatureWriter.h --- a/runner/JAMSFeatureWriter.h Wed Oct 15 13:30:25 2014 +0100 +++ b/runner/JAMSFeatureWriter.h Wed Oct 15 13:52:25 2014 +0100 @@ -62,7 +62,7 @@ typedef map RDFDescriptionMap; // by plugin id RDFDescriptionMap m_rdfDescriptions; - typedef map TrackMetadataMap; // track id -> json object + typedef map TrackMetadataMap; TrackMetadataMap m_metadata; typedef map DataMap;