diff runner/main.cpp @ 111:74f7ad72fee6

Simplify playlist handling (hoist it up a level)
author Chris Cannam
date Thu, 02 Oct 2014 15:21:16 +0100
parents fae326c22df5
children 0c2d8c945bbf
line wrap: on
line diff
--- a/runner/main.cpp	Thu Oct 02 14:54:09 2014 +0100
+++ b/runner/main.cpp	Thu Oct 02 15:21:16 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"
@@ -349,6 +350,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)
 {
@@ -696,6 +726,8 @@
         }
     }
 
+    sources = expandPlaylists(sources);
+
     bool good = true;
     QSet<QString> badSources;