changeset 166:e98b1abeb792 jams

Better track metadata
author Chris Cannam
date Wed, 15 Oct 2014 13:52:25 +0100
parents d0be35a305cc
children e5873fb4ffb3
files runner/JAMSFeatureWriter.cpp runner/JAMSFeatureWriter.h
diffstat 2 files changed, 22 insertions(+), 8 deletions(-) [+]
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);
     }
 
--- 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<QString, PluginRDFDescription> RDFDescriptionMap; // by plugin id
     RDFDescriptionMap m_rdfDescriptions;
 
-    typedef map<QString, QString> TrackMetadataMap; // track id -> json object
+    typedef map<QString, TrackMetadata> TrackMetadataMap;
     TrackMetadataMap m_metadata;
 
     typedef map<TrackTransformPair, QString> DataMap;