comparison 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
comparison
equal deleted inserted replaced
109:78a7c77ba432 111:74f7ad72fee6
33 33
34 #include "../version.h" 34 #include "../version.h"
35 35
36 #include "base/Exceptions.h" 36 #include "base/Exceptions.h"
37 #include "base/TempDirectory.h" 37 #include "base/TempDirectory.h"
38 #include "base/ProgressPrinter.h"
38 39
39 #include "data/fileio/AudioFileReaderFactory.h" 40 #include "data/fileio/AudioFileReaderFactory.h"
40 #include "data/fileio/PlaylistFileReader.h" 41 #include "data/fileio/PlaylistFileReader.h"
41 42
42 #include "transform/Transform.h" 43 #include "transform/Transform.h"
347 for (int i = 0; i < subdirs.size(); ++i) { 348 for (int i = 0; i < subdirs.size(); ++i) {
348 findSourcesRecursive(dir.filePath(subdirs[i]), addTo, found); 349 findSourcesRecursive(dir.filePath(subdirs[i]), addTo, found);
349 } 350 }
350 } 351 }
351 352
353 QStringList
354 expandPlaylists(QStringList sources)
355 {
356 QStringList expanded;
357 foreach (QString path, sources) {
358 cerr << "expandPlaylists: looking at " << path << endl;
359 if (QFileInfo(path).suffix().toLower() == "m3u") {
360 ProgressPrinter retrievalProgress("Opening playlist file...");
361 FileSource source(path, &retrievalProgress);
362 if (!source.isAvailable()) {
363 cerr << "ERROR: File or URL \"" << path.toStdString()
364 << "\" could not be located" << endl;
365 throw FileNotFound(path);
366 }
367 source.waitForData();
368 PlaylistFileReader reader(source);
369 if (reader.isOK()) {
370 vector<QString> files = reader.load();
371 for (int i = 0; i < (int)files.size(); ++i) {
372 expanded.push_back(files[i]);
373 }
374 }
375 } else {
376 // not a playlist
377 expanded.push_back(path);
378 }
379 }
380 return expanded;
381 }
352 382
353 int main(int argc, char **argv) 383 int main(int argc, char **argv)
354 { 384 {
355 QCoreApplication application(argc, argv); 385 QCoreApplication application(argc, argv);
356 386
694 sources.push_back(*i); 724 sources.push_back(*i);
695 } 725 }
696 } 726 }
697 } 727 }
698 728
729 sources = expandPlaylists(sources);
730
699 bool good = true; 731 bool good = true;
700 QSet<QString> badSources; 732 QSet<QString> badSources;
701 733
702 for (QStringList::const_iterator i = sources.begin(); 734 for (QStringList::const_iterator i = sources.begin();
703 i != sources.end(); ++i) { 735 i != sources.end(); ++i) {