comparison runner/FeatureExtractionManager.cpp @ 111:74f7ad72fee6

Simplify playlist handling (hoist it up a level)
author Chris Cannam
date Thu, 02 Oct 2014 15:21:16 +0100
parents 78a7c77ba432
children 0c2d8c945bbf
comparison
equal deleted inserted replaced
109:78a7c77ba432 111:74f7ad72fee6
38 using Vamp::HostExt::PluginWrapper; 38 using Vamp::HostExt::PluginWrapper;
39 39
40 #include "data/fileio/FileSource.h" 40 #include "data/fileio/FileSource.h"
41 #include "data/fileio/AudioFileReader.h" 41 #include "data/fileio/AudioFileReader.h"
42 #include "data/fileio/AudioFileReaderFactory.h" 42 #include "data/fileio/AudioFileReaderFactory.h"
43 #include "data/fileio/PlaylistFileReader.h"
44 #include "base/TempDirectory.h" 43 #include "base/TempDirectory.h"
45 #include "base/ProgressPrinter.h" 44 #include "base/ProgressPrinter.h"
46 #include "transform/TransformFactory.h" 45 #include "transform/TransformFactory.h"
47 #include "rdf/RDFTransformFactory.h" 46 #include "rdf/RDFTransformFactory.h"
48 #include "transform/FeatureWriter.h" 47 #include "transform/FeatureWriter.h"
432 return addFeatureExtractor(transform, writers); 431 return addFeatureExtractor(transform, writers);
433 } 432 }
434 433
435 void FeatureExtractionManager::addSource(QString audioSource) 434 void FeatureExtractionManager::addSource(QString audioSource)
436 { 435 {
437 if (QFileInfo(audioSource).suffix().toLower() == "m3u") {
438 ProgressPrinter retrievalProgress("Opening playlist file...");
439 FileSource source(audioSource, &retrievalProgress);
440 if (!source.isAvailable()) {
441 cerr << "ERROR: File or URL \"" << audioSource.toStdString()
442 << "\" could not be located" << endl;
443 throw FileNotFound(audioSource);
444 }
445 source.waitForData();
446 PlaylistFileReader reader(source);
447 if (reader.isOK()) {
448 vector<QString> files = reader.load();
449 for (int i = 0; i < (int)files.size(); ++i) {
450 addSource(files[i]);
451 }
452 return;
453 } else {
454 cerr << "ERROR: Playlist \"" << audioSource.toStdString()
455 << "\" could not be opened" << endl;
456 throw FileNotFound(audioSource);
457 }
458 }
459
460 std::cerr << "Have audio source: \"" << audioSource.toStdString() << "\"" << std::endl; 436 std::cerr << "Have audio source: \"" << audioSource.toStdString() << "\"" << std::endl;
461 437
462 // We don't actually do anything with it here, unless it's the 438 // We don't actually do anything with it here, unless it's the
463 // first audio source and we need it to establish default channel 439 // first audio source and we need it to establish default channel
464 // count and sample rate 440 // count and sample rate
509 } 485 }
510 486
511 void FeatureExtractionManager::extractFeatures(QString audioSource, bool force) 487 void FeatureExtractionManager::extractFeatures(QString audioSource, bool force)
512 { 488 {
513 if (m_plugins.empty()) return; 489 if (m_plugins.empty()) return;
514
515 if (QFileInfo(audioSource).suffix().toLower() == "m3u") {
516 FileSource source(audioSource);
517 PlaylistFileReader reader(source);
518 if (reader.isOK()) {
519 vector<QString> files = reader.load();
520 for (int i = 0; i < (int)files.size(); ++i) {
521 try {
522 extractFeatures(files[i], force);
523 } catch (const std::exception &e) {
524 if (!force) throw;
525 cerr << "ERROR: Feature extraction failed for playlist entry \""
526 << files[i].toStdString()
527 << "\": " << e.what() << endl;
528 // print a note only if we have more files to process
529 if (++i != (int)files.size()) {
530 cerr << "NOTE: \"--force\" option was provided, continuing (more errors may occur)" << endl;
531 }
532 }
533 }
534 return;
535 } else {
536 cerr << "ERROR: Playlist \"" << audioSource.toStdString()
537 << "\" could not be opened" << endl;
538 throw FileNotFound(audioSource);
539 }
540 }
541 490
542 testOutputFiles(audioSource); 491 testOutputFiles(audioSource);
543 492
544 if (m_sampleRate == 0) { 493 if (m_sampleRate == 0) {
545 throw FileOperationFailed 494 throw FileOperationFailed