diff runner/main.cpp @ 112:0c2d8c945bbf multiplex

Merge from default branch
author Chris Cannam
date Thu, 02 Oct 2014 15:23:25 +0100
parents de76b2df518f 74f7ad72fee6
children 1c0799754670
line wrap: on
line diff
--- a/runner/main.cpp	Thu Oct 02 14:54:48 2014 +0100
+++ b/runner/main.cpp	Thu Oct 02 15:23:25 2014 +0100
@@ -35,6 +35,7 @@
 
 #include "base/Exceptions.h"
 #include "base/TempDirectory.h"
+#include "base/ProgressPrinter.h"
 
 #include "data/fileio/AudioFileReaderFactory.h"
 #include "data/fileio/PlaylistFileReader.h"
@@ -346,6 +347,35 @@
     }
 }
 
+QStringList
+expandPlaylists(QStringList sources)
+{
+    QStringList expanded;
+    foreach (QString path, sources) {
+        cerr << "expandPlaylists: looking at " << path << endl;
+        if (QFileInfo(path).suffix().toLower() == "m3u") {
+            ProgressPrinter retrievalProgress("Opening playlist file...");
+            FileSource source(path, &retrievalProgress);
+            if (!source.isAvailable()) {
+                cerr << "ERROR: File or URL \"" << path.toStdString()
+                     << "\" could not be located" << endl;
+                throw FileNotFound(path);
+            }
+            source.waitForData();
+            PlaylistFileReader reader(source);
+            if (reader.isOK()) {
+                vector<QString> files = reader.load();
+                for (int i = 0; i < (int)files.size(); ++i) {
+                    expanded.push_back(files[i]);
+                }
+            }
+        } else {
+            // not a playlist
+            expanded.push_back(path);
+        }
+    }
+    return expanded;
+}
 
 int main(int argc, char **argv)
 {
@@ -689,6 +719,8 @@
         }
     }
 
+    sources = expandPlaylists(sources);
+
     bool good = true;
     QSet<QString> badSources;
 
@@ -759,7 +791,7 @@
                 std::cerr << "Extracting features for: \"" << i->toStdString()
                           << "\"" << std::endl;
                 try {
-                    manager.extractFeatures(*i, force);
+                    manager.extractFeatures(*i);
                 } catch (const std::exception &e) {
                     cerr << "ERROR: Feature extraction failed for \""
                          << i->toStdString() << "\": " << e.what() << endl;