Example #1
0
QStringList writeKeyToFilename(const QString& filename, KeyFinder::key_t key, const Preferences & prefs) {
  QString dataToWrite = prefs.getKeyCode(key);
  QFile file(filename);
  QString path = file.fileName().left(file.fileName().lastIndexOf("/") + 1);
  QString extn = file.fileName().mid(file.fileName().lastIndexOf("."));
  QString name = file.fileName().mid(file.fileName().lastIndexOf("/") + 1);
  name = name.left(name.length() - extn.length());
  QStringList written;
  QString newName = prefs.newString(dataToWrite, name, METADATA_CHARLIMIT_FILENAME, prefs.getMetadataWriteFilename());
  if (newName != "") {
    name = newName;
  }
  if (file.rename(path + name + extn)) {
    written << path << name << extn;
  }
  return written;
}
Example #2
0
int commandLineInterface(int argc, char* argv[]){

  QString filePath = "";
  bool writeToTags = false;

  for(int i = 1; i < argc; i++){
    if(std::strcmp(argv[i], "-f") == 0 && i+1 < argc)
      filePath = argv[++i];
    else if (std::strcmp(argv[i], "-w") == 0)
      writeToTags = true;
  }
  if(filePath.isEmpty())
    return -1; // not a valid CLI attempt, launch GUI

  Preferences prefs;
  AsyncFileObject object(filePath, prefs, 0);
  KeyFinderResultWrapper result = keyDetectionProcess(object);
  if(!result.errorMessage.isEmpty()){
    std::cerr << result.errorMessage.toLocal8Bit().constData();
    return 1;
  }

  std::cout << prefs.getKeyCode(result.core.globalKeyEstimate).toLocal8Bit().constData();

  if(writeToTags){
    TagLibMetadata md(filePath);
    QString written = md.writeKeyToMetadata(result.core.globalKeyEstimate,prefs);
    if(written.isEmpty()){
      std::cerr << "Could not write to tags" << std::endl;
      return 2;
    }
  }

  return 0;

}