void AnalyzeTask::run_ex(void) { int fileType = fileTypeNormal; QString currentFile = QDir::fromNativeSeparators(m_inputFile); qDebug("Analyzing: %s", MUTILS_UTF8(currentFile)); AudioFileModel file = analyzeFile(currentFile, &fileType); if(*m_abortFlag) { qWarning("Operation cancelled by user!"); return; } switch(fileType) { case fileTypeDenied: qWarning("Cannot access file for reading, skipping!"); break; case fileTypeCDDA: qWarning("Dummy CDDA file detected, skipping!"); break; default: if(file.metaInfo().title().isEmpty() || file.techInfo().containerType().isEmpty() || file.techInfo().audioType().isEmpty()) { fileType = fileTypeUnknown; if(!QFileInfo(currentFile).suffix().compare("cue", Qt::CaseInsensitive)) { qWarning("Cue Sheet file detected, skipping!"); fileType = fileTypeCueSheet; } else if(!QFileInfo(currentFile).suffix().compare("avs", Qt::CaseInsensitive)) { qDebug("Found a potential Avisynth script, investigating..."); if(analyzeAvisynthFile(currentFile, file)) { fileType = fileTypeNormal; } else { qDebug("Rejected Avisynth file: %s", MUTILS_UTF8(file.filePath())); } } else { qDebug("Rejected file of unknown type: %s", MUTILS_UTF8(file.filePath())); } } break; } //Emit the file now! emit fileAnalyzed(m_taskId, fileType, file); }
void AnalyzeTask::retrieveCover(AudioFileModel &audioFile, cover_t coverType, const QByteArray &coverData) { qDebug("Retrieving cover!"); QString extension; switch(coverType) { case coverPng: extension = QString::fromLatin1("png"); break; case coverGif: extension = QString::fromLatin1("gif"); break; default: extension = QString::fromLatin1("jpg"); break; } if(!(QImage::fromData(coverData, extension.toUpper().toLatin1().constData()).isNull())) { QFile coverFile(QString("%1/%2.%3").arg(lamexp_temp_folder2(), lamexp_rand_str(), extension)); if(coverFile.open(QIODevice::WriteOnly)) { coverFile.write(coverData); coverFile.close(); audioFile.metaInfo().setCover(coverFile.fileName(), true); } } else { qWarning("Image data seems to be invalid :-("); } }
int MetaInfoDialog::exec(AudioFileModel &audioFile, bool allowUp, bool allowDown) { MetaInfoModel *model = new MetaInfoModel(&audioFile); tableView->setModel(model); tableView->show(); frameArtwork->hide(); setWindowTitle(tr("Meta Information: %1").arg(QFileInfo(audioFile.filePath()).fileName())); editButton->setEnabled(true); upButton->setEnabled(allowUp); downButton->setEnabled(allowDown); buttonArtwork->setChecked(false); if(!audioFile.fileCover().isEmpty()) { QImage artwork; if(artwork.load(audioFile.fileCover())) { if((artwork.width() > 256) || (artwork.height() > 256)) { artwork = artwork.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation); } labelArtwork->setPixmap(QPixmap::fromImage(artwork)); } else { qWarning("Error: Failed to load cover art!"); labelArtwork->setPixmap(QPixmap::fromImage(QImage(":/images/CD.png"))); } } else { labelArtwork->setPixmap(QPixmap::fromImage(QImage(":/images/CD.png"))); } int iResult = QDialog::exec(); tableView->setModel(NULL); LAMEXP_DELETE(model); return iResult; }
void MetaInfoModel::assignInfoFrom(const AudioFileModel &file) { beginResetModel(); const unsigned int position = m_metaInfo->position(); m_metaInfo->update(file.metaInfo(), true); if(m_offset) { m_metaInfo->setTitle(QString()); m_metaInfo->setPosition(position ? UINT_MAX : 0); m_metaInfo->setCover(QString(), false); } endResetModel(); }
void FileListModel::addFile(const AudioFileModel &file) { const QString key = MAKE_KEY(file.filePath()); const bool flag = (!m_blockUpdates); if(!m_fileStore.contains(key)) { if(flag) beginInsertRows(QModelIndex(), m_fileList.count(), m_fileList.count()); m_fileStore.insert(key, file); m_fileList.append(key); if(flag) endInsertRows(); emit rowAppended(); } }
bool FileListModel::setFile(const QModelIndex &index, const AudioFileModel &audioFile) { if(index.row() >= 0 && index.row() < m_fileList.count()) { const QString oldKey = m_fileList.at(index.row()); const QString newKey = MAKE_KEY(audioFile.filePath()); beginResetModel(); m_fileList.replace(index.row(), newKey); m_fileStore.remove(oldKey); m_fileStore.insert(newKey, audioFile); endResetModel(); return true; } else { return false; } }
void AnalyzeTask::retrieveCover(AudioFileModel &audioFile, const QString &coverType, const QString &coverData) { const QByteArray content = QByteArray::fromBase64(coverData.toLatin1()); const QString type = m_mimeTypes.value(coverType.toLower()); qDebug("Retrieving cover! (mime=\"%s\", type=\"%s\", len=%d)", MUTILS_L1STR(coverType), MUTILS_L1STR(type), content.size()); if(!QImage::fromData(content, type.isEmpty() ? NULL : MUTILS_L1STR(type.toUpper())).isNull()) { QFile coverFile(QString("%1/%2.%3").arg(MUtils::temp_folder(), MUtils::next_rand_str(), type.isEmpty() ? QLatin1String("jpg") : type)); if(coverFile.open(QIODevice::WriteOnly)) { coverFile.write(content); coverFile.close(); audioFile.metaInfo().setCover(coverFile.fileName(), true); } } else { qWarning("Image data seems to be invalid! [Header:%s]", content.left(32).toHex().constData()); } }
void AnalyzeTask::retrieveCover(AudioFileModel &audioFile, const quint32 coverType, const QByteArray &coverData) { qDebug("Retrieving cover! (MIME_TYPES_MAX=%u)", MIME_TYPES_MAX); static const QString ext = QString::fromLatin1(MIME_TYPES[qBound(0U, coverType, MIME_TYPES_MAX)].ext[0]); if(!(QImage::fromData(coverData, ext.toUpper().toLatin1().constData()).isNull())) { QFile coverFile(QString("%1/%2.%3").arg(MUtils::temp_folder(), MUtils::rand_str(), ext)); if(coverFile.open(QIODevice::WriteOnly)) { coverFile.write(coverData); coverFile.close(); audioFile.metaInfo().setCover(coverFile.fileName(), true); } } else { qWarning("Image data seems to be invalid :-("); } }
bool FLACEncoder::encode(const QString &sourceFile, const AudioFileModel &metaInfo, const QString &outputFile, volatile bool *abortFlag) { QProcess process; QStringList args; args << QString("-%1").arg(QString::number(qBound(0, m_configBitrate, 8))); args << "--channel-map=none"; if(!metaInfo.fileName().isEmpty()) args << "-T" << QString("title=%1").arg(cleanTag(metaInfo.fileName())); if(!metaInfo.fileArtist().isEmpty()) args << "-T" << QString("artist=%1").arg(cleanTag(metaInfo.fileArtist())); if(!metaInfo.fileAlbum().isEmpty()) args << "-T" << QString("album=%1").arg(cleanTag(metaInfo.fileAlbum())); if(!metaInfo.fileGenre().isEmpty()) args << "-T" << QString("genre=%1").arg(cleanTag(metaInfo.fileGenre())); if(!metaInfo.fileComment().isEmpty()) args << "-T" << QString("comment=%1").arg(cleanTag(metaInfo.fileComment())); if(metaInfo.fileYear()) args << "-T" << QString("date=%1").arg(QString::number(metaInfo.fileYear())); if(metaInfo.filePosition()) args << "-T" << QString("track=%1").arg(QString::number(metaInfo.filePosition())); if(!metaInfo.fileCover().isEmpty()) args << QString("--picture=%1").arg(metaInfo.fileCover()); //args << "--tv" << QString().sprintf("Encoder=LameXP v%d.%02d.%04d [%s]", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build(), lamexp_version_release()); if(!m_configCustomParams.isEmpty()) args << m_configCustomParams.split(" ", QString::SkipEmptyParts); args << "-f" << "-o" << QDir::toNativeSeparators(outputFile); args << QDir::toNativeSeparators(sourceFile); if(!startProcess(process, m_binary, args)) { return false; } bool bTimeout = false; bool bAborted = false; int prevProgress = -1; QRegExp regExp("\\b(\\d+)% complete"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("FLAC process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine().replace('\b', char(0x20)); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp.cap(1).toInt(&ok); if(ok && (progress > prevProgress)) { emit statusUpdated(progress); prevProgress = qMin(progress + 2, 99); } } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS) { return false; } return true; }
bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel &metaInfo, const QString &outputFile, volatile bool *abortFlag) { const unsigned int fileDuration = metaInfo.fileDuration(); QProcess process; QStringList args; const QString baseName = QFileInfo(outputFile).fileName(); switch(m_configRCMode) { case SettingsModel::VBRMode: args << "-q" << QString().sprintf("%.2f", qBound(0.0, static_cast<double>(m_configBitrate) / 20.0, 1.0)); break; case SettingsModel::ABRMode: args << "-br" << QString::number(qMax(32, qMin(500, (m_configBitrate * 8))) * 1000); break; case SettingsModel::CBRMode: args << "-cbr" << QString::number(qMax(32, qMin(500, (m_configBitrate * 8))) * 1000); break; default: throw "Bad rate-control mode!"; break; } if(m_configEnable2Pass && (m_configRCMode == SettingsModel::ABRMode)) { args << "-2pass"; } switch(m_configProfile) { case 1: args << "-lc"; //Forces use of LC AAC profile break; case 2: args << "-he"; //Forces use of HE AAC profile break; case 3: args << "-hev2"; //Forces use of HEv2 AAC profile break; } if(!m_configCustomParams.isEmpty()) args << m_configCustomParams.split(" ", QString::SkipEmptyParts); args << "-if" << QDir::toNativeSeparators(sourceFile); args << "-of" << QDir::toNativeSeparators(outputFile); if(!startProcess(process, m_binary_enc, args)) { return false; } bool bTimeout = false; bool bAborted = false; int prevProgress = -1; QRegExp regExp("Processed\\s+(\\d+)\\s+seconds"); QRegExp regExp_pass1("First\\s+pass:\\s+processed\\s+(\\d+)\\s+seconds"); QRegExp regExp_pass2("Second\\s+pass:\\s+processed\\s+(\\d+)\\s+seconds"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("NeroAacEnc process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp_pass1.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp_pass1.cap(1).toInt(&ok); if(ok && (fileDuration > 0)) { int newProgress = qRound((static_cast<double>(progress) / static_cast<double>(fileDuration)) * 50.0); if(newProgress > prevProgress) { emit statusUpdated(newProgress); prevProgress = qMin(newProgress + 2, 99); } } } else if(regExp_pass2.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp_pass2.cap(1).toInt(&ok); if(ok && (fileDuration > 0)) { int newProgress = qRound((static_cast<double>(progress) / static_cast<double>(fileDuration)) * 50.0) + 50; if(newProgress > prevProgress) { emit statusUpdated(newProgress); prevProgress = qMin(newProgress + 2, 99); } } } else if(regExp.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp.cap(1).toInt(&ok); if(ok && (fileDuration > 0)) { int newProgress = qRound((static_cast<double>(progress) / static_cast<double>(fileDuration)) * 100.0); if(newProgress > prevProgress) { emit statusUpdated(newProgress); prevProgress = qMin(newProgress + 2, 99); } } } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS) { return false; } emit messageLogged("\n-------------------------------\n"); args.clear(); args << QDir::toNativeSeparators(outputFile); if(!metaInfo.fileName().isEmpty()) args << QString("-meta:title=%1").arg(cleanTag(metaInfo.fileName())); if(!metaInfo.fileArtist().isEmpty()) args << QString("-meta:artist=%1").arg(cleanTag(metaInfo.fileArtist())); if(!metaInfo.fileAlbum().isEmpty()) args << QString("-meta:album=%1").arg(cleanTag(metaInfo.fileAlbum())); if(!metaInfo.fileGenre().isEmpty()) args << QString("-meta:genre=%1").arg(cleanTag(metaInfo.fileGenre())); if(!metaInfo.fileComment().isEmpty()) args << QString("-meta:comment=%1").arg(cleanTag(metaInfo.fileComment())); if(metaInfo.fileYear()) args << QString("-meta:year=%1").arg(QString::number(metaInfo.fileYear())); if(metaInfo.filePosition()) args << QString("-meta:track=%1").arg(QString::number(metaInfo.filePosition())); if(!metaInfo.fileCover().isEmpty()) args << QString("-add-cover:%1:%2").arg("front", metaInfo.fileCover()); if(!startProcess(process, m_binary_tag, args)) { return false; } bTimeout = false; while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("NeroAacTag process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS) { return false; } return true; }
bool AnalyzeTask::analyzeAvisynthFile(const QString &filePath, AudioFileModel &info) { QProcess process; MUtils::init_process(process, QFileInfo(m_avs2wavBin).absolutePath()); process.start(m_avs2wavBin, QStringList() << QDir::toNativeSeparators(filePath) << "?"); if(!process.waitForStarted()) { qWarning("AVS2WAV process failed to create!"); qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData()); process.kill(); process.waitForFinished(-1); return false; } bool bInfoHeaderFound = false; while(process.state() != QProcess::NotRunning) { if(MUTILS_BOOLIFY(m_abortFlag)) { process.kill(); qWarning("Process was aborted on user request!"); break; } if(!process.waitForReadyRead()) { if(process.state() == QProcess::Running) { qWarning("AVS2WAV time out. Killing process and skipping file!"); process.kill(); process.waitForFinished(-1); return false; } } while(process.canReadLine()) { const QString line = QString::fromUtf8(process.readLine().constData()).simplified(); if(!line.isEmpty()) { if(bInfoHeaderFound) { const qint32 index = line.indexOf(':'); if (index > 0) { const QString key = line.left(index).trimmed(); const QString val = line.mid(index + 1).trimmed(); if (!(key.isEmpty() || val.isEmpty())) { switch (m_avisynthIdx.value(key.toLower(), MI_propertyId_t(-1))) { case propertyId_duration: SET_OPTIONAL(quint32, parseUnsigned(val, _tmp), info.techInfo().setDuration(_tmp)); break; case propertyId_samplingrate: SET_OPTIONAL(quint32, parseUnsigned(val, _tmp), info.techInfo().setAudioSamplerate(_tmp)); break; case propertyId_channel_s_: SET_OPTIONAL(quint32, parseUnsigned(val, _tmp), info.techInfo().setAudioChannels(_tmp)); break; case propertyId_bitdepth: SET_OPTIONAL(quint32, parseUnsigned(val, _tmp), info.techInfo().setAudioBitdepth(_tmp)); break; } } } } else { if(line.contains("[Audio Info]", Qt::CaseInsensitive)) { info.techInfo().setAudioType("Avisynth"); info.techInfo().setContainerType("Avisynth"); bInfoHeaderFound = true; } } } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } //Check exit code switch(process.exitCode()) { case 0: qDebug("Avisynth script was analyzed successfully."); return true; break; case -5: qWarning("It appears that Avisynth is not installed on the system!"); return false; break; default: qWarning("Failed to open the Avisynth script, bad AVS file?"); return false; break; } }
void AnalyzeTask::parseProperty(const QString &value, const MI_propertyId_t propertyIdx, AudioFileModel &audioFile, QString &coverMimeType) { #if MUTILS_DEBUG qDebug("Property #%d = \"%s\"", propertyIdx, MUTILS_UTF8(value.left(24))); #endif switch (propertyIdx) { case propertyId_container: audioFile.techInfo().setContainerType(value); return; case propertyId_container_profile: audioFile.techInfo().setContainerProfile(value); return; case propertyId_duration: SET_OPTIONAL(double, parseFloat(value, _tmp), audioFile.techInfo().setDuration(qRound(_tmp))); return; case propertyId_title: audioFile.metaInfo().setTitle(value); return; case propertyId_artist: audioFile.metaInfo().setArtist(value); return; case propertyId_album: audioFile.metaInfo().setAlbum(value); return; case propertyId_genre: audioFile.metaInfo().setGenre(value); return; case propertyId_released_date: SET_OPTIONAL(quint32, parseYear(value, _tmp), audioFile.metaInfo().setYear(_tmp)); return; case propertyId_track_position: SET_OPTIONAL(quint32, parseUnsigned(value, _tmp), audioFile.metaInfo().setPosition(_tmp)); return; case propertyId_comment: audioFile.metaInfo().setComment(value); return; case propertyId_format: audioFile.techInfo().setAudioType(value); return; case propertyId_format_version: audioFile.techInfo().setAudioVersion(value); return; case propertyId_format_profile: audioFile.techInfo().setAudioProfile(value); return; case propertyId_channel_s_: SET_OPTIONAL(quint32, parseUnsigned(value, _tmp), audioFile.techInfo().setAudioChannels(_tmp)); return; case propertyId_samplingrate: SET_OPTIONAL(quint32, parseUnsigned(value, _tmp), audioFile.techInfo().setAudioSamplerate(_tmp)); return; case propertyId_bitdepth: SET_OPTIONAL(quint32, parseUnsigned(value, _tmp), audioFile.techInfo().setAudioBitdepth(_tmp)); return; case propertyId_bitrate: SET_OPTIONAL(quint32, parseUnsigned(value, _tmp), audioFile.techInfo().setAudioBitrate(DIV_RND(_tmp, 1000U))); return; case propertyId_bitrate_mode: SET_OPTIONAL(quint32, parseRCMode(value, _tmp), audioFile.techInfo().setAudioBitrateMode(_tmp)); return; case propertyId_encoded_library: audioFile.techInfo().setAudioEncodeLib(cleanAsciiStr(value)); return; case propertyId_cover_mime: coverMimeType = value; return; case propertyId_cover_data: retrieveCover(audioFile, coverMimeType, value); return; default: MUTILS_THROW_FMT("Invalid property ID: %d", propertyIdx); } }
bool AnalyzeTask::analyzeAvisynthFile(const QString &filePath, AudioFileModel &info) { QProcess process; MUtils::init_process(process, QFileInfo(m_avs2wavBin).absolutePath()); process.start(m_avs2wavBin, QStringList() << QDir::toNativeSeparators(filePath) << "?"); if(!process.waitForStarted()) { qWarning("AVS2WAV process failed to create!"); qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData()); process.kill(); process.waitForFinished(-1); return false; } bool bInfoHeaderFound = false; while(process.state() != QProcess::NotRunning) { if(*m_abortFlag) { process.kill(); qWarning("Process was aborted on user request!"); break; } if(!process.waitForReadyRead()) { if(process.state() == QProcess::Running) { qWarning("AVS2WAV time out. Killing process and skipping file!"); process.kill(); process.waitForFinished(-1); return false; } } QByteArray data; while(process.canReadLine()) { QString line = QString::fromUtf8(process.readLine().constData()).simplified(); if(!line.isEmpty()) { int index = line.indexOf(':'); if(index > 0) { QString key = line.left(index).trimmed(); QString val = line.mid(index+1).trimmed(); if(bInfoHeaderFound && !key.isEmpty() && !val.isEmpty()) { if(key.compare("TotalSeconds", Qt::CaseInsensitive) == 0) { bool ok = false; unsigned int duration = val.toUInt(&ok); if(ok) info.techInfo().setDuration(duration); } if(key.compare("SamplesPerSec", Qt::CaseInsensitive) == 0) { bool ok = false; unsigned int samplerate = val.toUInt(&ok); if(ok) info.techInfo().setAudioSamplerate (samplerate); } if(key.compare("Channels", Qt::CaseInsensitive) == 0) { bool ok = false; unsigned int channels = val.toUInt(&ok); if(ok) info.techInfo().setAudioChannels(channels); } if(key.compare("BitsPerSample", Qt::CaseInsensitive) == 0) { bool ok = false; unsigned int bitdepth = val.toUInt(&ok); if(ok) info.techInfo().setAudioBitdepth(bitdepth); } } } else { if(line.contains("[Audio Info]", Qt::CaseInsensitive)) { info.techInfo().setAudioType("Avisynth"); info.techInfo().setContainerType("Avisynth"); bInfoHeaderFound = true; } } } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } //Check exit code switch(process.exitCode()) { case 0: qDebug("Avisynth script was analyzed successfully."); return true; break; case -5: qWarning("It appears that Avisynth is not installed on the system!"); return false; break; default: qWarning("Failed to open the Avisynth script, bad AVS file?"); return false; break; } }
void AnalyzeTask::updateInfo(AudioFileModel &audioFile, bool &skipNext, QPair<quint32, quint32> &id_val, quint32 &coverType, QByteArray &coverData, const QString &key, const QString &value) { //qWarning("'%s' -> '%s'", MUTILS_UTF8(key), MUTILS_UTF8(value)); /*New Stream*/ if(IS_KEY("Gen_ID") || IS_KEY("Aud_ID")) { if(value.isEmpty()) { skipNext = false; } else { //We ignore all ID's, except for the lowest one! bool ok = false; unsigned int id = value.toUInt(&ok); if(ok) { if(IS_KEY("Gen_ID")) { id_val.first = qMin(id_val.first, id); skipNext = (id > id_val.first); } if(IS_KEY("Aud_ID")) { id_val.second = qMin(id_val.second, id); skipNext = (id > id_val.second); } } else { skipNext = true; } } if(skipNext) { qWarning("Skipping info for non-primary stream!"); } return; } /*Skip or empty?*/ if((skipNext) || value.isEmpty()) { return; } /*Playlist file?*/ if(IS_KEY("Aud_Source")) { skipNext = true; audioFile.techInfo().setContainerType(QString()); audioFile.techInfo().setAudioType(QString()); qWarning("Skipping info for playlist file!"); return; } /*General Section*/ if(IS_SEC("Gen")) { if(IS_KEY("Gen_Format")) { audioFile.techInfo().setContainerType(value); } else if(IS_KEY("Gen_Format_Profile")) { audioFile.techInfo().setContainerProfile(value); } else if(IS_KEY("Gen_Title") || IS_KEY("Gen_Track")) { audioFile.metaInfo().setTitle(value); } else if(IS_KEY("Gen_Duration")) { unsigned int tmp = parseDuration(value); if(tmp > 0) audioFile.techInfo().setDuration(tmp); } else if(IS_KEY("Gen_Artist") || IS_KEY("Gen_Performer")) { audioFile.metaInfo().setArtist(value); } else if(IS_KEY("Gen_Album")) { audioFile.metaInfo().setAlbum(value); } else if(IS_KEY("Gen_Genre")) { audioFile.metaInfo().setGenre(value); } else if(IS_KEY("Gen_Released_Date") || IS_KEY("Gen_Recorded_Date")) { unsigned int tmp = parseYear(value); if(tmp > 0) audioFile.metaInfo().setYear(tmp); } else if(IS_KEY("Gen_Comment")) { audioFile.metaInfo().setComment(value); } else if(IS_KEY("Gen_Track/Position")) { bool ok = false; unsigned int tmp = value.toUInt(&ok); if(ok) audioFile.metaInfo().setPosition(tmp); } else if(IS_KEY("Gen_Cover") || IS_KEY("Gen_Cover_Type")) { if(coverType == UINT_MAX) { coverType = 0; } } else if(IS_KEY("Gen_Cover_Mime")) { QString temp = FIRST_TOK(value); for (quint32 i = 0; MIME_TYPES[i].type; i++) { if (temp.compare(QString::fromLatin1(MIME_TYPES[i].type), Qt::CaseInsensitive) == 0) { coverType = i; break; } } } else if(IS_KEY("Gen_Cover_Data")) { if(!coverData.isEmpty()) coverData.clear(); coverData.append(QByteArray::fromBase64(FIRST_TOK(value).toLatin1())); } else { qWarning("Unknown key '%s' with value '%s' found!", MUTILS_UTF8(key), MUTILS_UTF8(value)); } return; } /*Audio Section*/ if(IS_SEC("Aud")) { if(IS_KEY("Aud_Format")) { audioFile.techInfo().setAudioType(value); } else if(IS_KEY("Aud_Format_Profile")) { audioFile.techInfo().setAudioProfile(value); } else if(IS_KEY("Aud_Format_Version")) { audioFile.techInfo().setAudioVersion(value); } else if(IS_KEY("Aud_Channel(s)")) { bool ok = false; unsigned int tmp = value.toUInt(&ok); if(ok) audioFile.techInfo().setAudioChannels(tmp); } else if(IS_KEY("Aud_SamplingRate")) { bool ok = false; unsigned int tmp = value.toUInt(&ok); if(ok) audioFile.techInfo().setAudioSamplerate(tmp); } else if(IS_KEY("Aud_BitDepth")) { bool ok = false; unsigned int tmp = value.toUInt(&ok); if(ok) audioFile.techInfo().setAudioBitdepth(tmp); } else if(IS_KEY("Aud_Duration")) { unsigned int tmp = parseDuration(value); if(tmp > 0) audioFile.techInfo().setDuration(tmp); } else if(IS_KEY("Aud_BitRate")) { bool ok = false; unsigned int tmp = value.toUInt(&ok); if(ok) audioFile.techInfo().setAudioBitrate(tmp/1000); } else if(IS_KEY("Aud_BitRate_Mode")) { if(!value.compare("CBR", Qt::CaseInsensitive)) audioFile.techInfo().setAudioBitrateMode(AudioFileModel::BitrateModeConstant); if(!value.compare("VBR", Qt::CaseInsensitive)) audioFile.techInfo().setAudioBitrateMode(AudioFileModel::BitrateModeVariable); } else if(IS_KEY("Aud_Encoded_Library")) { audioFile.techInfo().setAudioEncodeLib(value); } else { qWarning("Unknown key '%s' with value '%s' found!", MUTILS_UTF8(key), MUTILS_UTF8(value)); } return; } /*Section not recognized*/ qWarning("Unknown section: %s", MUTILS_UTF8(key)); }
bool VorbisEncoder::encode(const QString &sourceFile, const AudioFileModel &metaInfo, const QString &outputFile, volatile bool *abortFlag) { QProcess process; QStringList args; const QString baseName = QFileInfo(outputFile).fileName(); switch(m_configRCMode) { case SettingsModel::VBRMode: args << "-q" << QString::number(qMax(-2, qMin(10, m_configBitrate))); break; case SettingsModel::ABRMode: args << "-b" << QString::number(qMax(32, qMin(500, (m_configBitrate * 8)))); break; default: throw "Bad rate-control mode!"; break; } if((m_configBitrateMaximum > 0) && (m_configBitrateMinimum > 0) && (m_configBitrateMinimum <= m_configBitrateMaximum)) { args << "--min-bitrate" << QString::number(qMin(qMax(m_configBitrateMinimum, 32), 500)); args << "--max-bitrate" << QString::number(qMin(qMax(m_configBitrateMaximum, 32), 500)); } if(m_configSamplingRate > 0) { args << "--resample" << QString::number(m_configSamplingRate) << "--converter" << QString::number(0); } if(!metaInfo.fileName().isEmpty()) args << "-t" << metaInfo.fileName(); if(!metaInfo.fileArtist().isEmpty()) args << "-a" << metaInfo.fileArtist(); if(!metaInfo.fileAlbum().isEmpty()) args << "-l" << metaInfo.fileAlbum(); if(!metaInfo.fileGenre().isEmpty()) args << "-G" << metaInfo.fileGenre(); if(!metaInfo.fileComment().isEmpty()) args << "-c" << QString("comment=%1").arg(metaInfo.fileComment()); if(metaInfo.fileYear()) args << "-d" << QString::number(metaInfo.fileYear()); if(metaInfo.filePosition()) args << "-N" << QString::number(metaInfo.filePosition()); //args << "--tv" << QString().sprintf("Encoder=LameXP v%d.%02d.%04d [%s]", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build(), lamexp_version_release()); if(!m_configCustomParams.isEmpty()) args << m_configCustomParams.split(" ", QString::SkipEmptyParts); args << "-o" << QDir::toNativeSeparators(outputFile); args << QDir::toNativeSeparators(sourceFile); if(!startProcess(process, m_binary, args)) { return false; } bool bTimeout = false; bool bAborted = false; int prevProgress = -1; QRegExp regExp("\\[.*(\\d+)[.,](\\d+)%\\]"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("OggEnc process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp.cap(1).toInt(&ok); if(ok && (progress > prevProgress)) { emit statusUpdated(progress); prevProgress = qMin(progress + 2, 99); } } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitStatus() != QProcess::NormalExit) { return false; } return true; }
void AnalyzeTask::updateInfo(AudioFileModel &audioFile, bool *skipNext, unsigned int *id_val, cover_t *coverType, QByteArray *coverData, const QString &key, const QString &value) { //qWarning("'%s' -> '%s'", QUTF8(key), QUTF8(value)); /*New Stream*/ if(IS_KEY("Gen_ID") || IS_KEY("Aud_ID")) { if(value.isEmpty()) { *skipNext = false; } else { //We ignore all ID's, except for the lowest one! bool ok = false; unsigned int id = value.toUInt(&ok); if(ok) { if(IS_KEY("Gen_ID")) { id_val[0] = qMin(id_val[0], id); *skipNext = (id > id_val[0]); } if(IS_KEY("Aud_ID")) { id_val[1] = qMin(id_val[1], id); *skipNext = (id > id_val[1]); } } else { *skipNext = true; } } if(*skipNext) { qWarning("Skipping info for non-primary stream!"); } return; } /*Skip or empty?*/ if((*skipNext) || value.isEmpty()) { return; } /*Playlist file?*/ if(IS_KEY("Aud_Source")) { *skipNext = true; audioFile.techInfo().setContainerType(QString()); audioFile.techInfo().setAudioType(QString()); qWarning("Skipping info for playlist file!"); return; } /*General Section*/ if(IS_SEC("Gen")) { if(IS_KEY("Gen_Format")) { audioFile.techInfo().setContainerType(value); } else if(IS_KEY("Gen_Format_Profile")) { audioFile.techInfo().setContainerProfile(value); } else if(IS_KEY("Gen_Title") || IS_KEY("Gen_Track")) { audioFile.metaInfo().setTitle(value); } else if(IS_KEY("Gen_Duration")) { unsigned int tmp = parseDuration(value); if(tmp > 0) audioFile.techInfo().setDuration(tmp); } else if(IS_KEY("Gen_Artist") || IS_KEY("Gen_Performer")) { audioFile.metaInfo().setArtist(value); } else if(IS_KEY("Gen_Album")) { audioFile.metaInfo().setAlbum(value); } else if(IS_KEY("Gen_Genre")) { audioFile.metaInfo().setGenre(value); } else if(IS_KEY("Gen_Released_Date") || IS_KEY("Gen_Recorded_Date")) { unsigned int tmp = parseYear(value); if(tmp > 0) audioFile.metaInfo().setYear(tmp); } else if(IS_KEY("Gen_Comment")) { audioFile.metaInfo().setComment(value); } else if(IS_KEY("Gen_Track/Position")) { bool ok = false; unsigned int tmp = value.toUInt(&ok); if(ok) audioFile.metaInfo().setPosition(tmp); } else if(IS_KEY("Gen_Cover") || IS_KEY("Gen_Cover_Type")) { if(*coverType == coverNone) { *coverType = coverJpeg; } } else if(IS_KEY("Gen_Cover_Mime")) { QString temp = FIRST_TOK(value); if(!temp.compare("image/jpeg", Qt::CaseInsensitive)) *coverType = coverJpeg; else if(!temp.compare("image/png", Qt::CaseInsensitive)) *coverType = coverPng; else if(!temp.compare("image/gif", Qt::CaseInsensitive)) *coverType = coverGif; } else if(IS_KEY("Gen_Cover_Data")) { if(!coverData->isEmpty()) coverData->clear(); coverData->append(QByteArray::fromBase64(FIRST_TOK(value).toLatin1())); } else { qWarning("Unknown key '%s' with value '%s' found!", QUTF8(key), QUTF8(value)); } return; } /*Audio Section*/ if(IS_SEC("Aud")) { if(IS_KEY("Aud_Format")) { audioFile.techInfo().setAudioType(value); } else if(IS_KEY("Aud_Format_Profile")) { audioFile.techInfo().setAudioProfile(value); } else if(IS_KEY("Aud_Format_Version")) { audioFile.techInfo().setAudioVersion(value); } else if(IS_KEY("Aud_Channel(s)")) { bool ok = false; unsigned int tmp = value.toUInt(&ok); if(ok) audioFile.techInfo().setAudioChannels(tmp); } else if(IS_KEY("Aud_SamplingRate")) { bool ok = false; unsigned int tmp = value.toUInt(&ok); if(ok) audioFile.techInfo().setAudioSamplerate(tmp); } else if(IS_KEY("Aud_BitDepth")) { bool ok = false; unsigned int tmp = value.toUInt(&ok); if(ok) audioFile.techInfo().setAudioBitdepth(tmp); } else if(IS_KEY("Aud_Duration")) { unsigned int tmp = parseDuration(value); if(tmp > 0) audioFile.techInfo().setDuration(tmp); } else if(IS_KEY("Aud_BitRate")) { bool ok = false; unsigned int tmp = value.toUInt(&ok); if(ok) audioFile.techInfo().setAudioBitrate(tmp/1000); } else if(IS_KEY("Aud_BitRate_Mode")) { if(!value.compare("CBR", Qt::CaseInsensitive)) audioFile.techInfo().setAudioBitrateMode(AudioFileModel::BitrateModeConstant); if(!value.compare("VBR", Qt::CaseInsensitive)) audioFile.techInfo().setAudioBitrateMode(AudioFileModel::BitrateModeVariable); } else if(IS_KEY("Aud_Encoded_Library")) { audioFile.techInfo().setAudioEncodeLib(value); } else { qWarning("Unknown key '%s' with value '%s' found!", QUTF8(key), QUTF8(value)); } return; } /*Section not recognized*/ qWarning("Unknown section: %s", QUTF8(key)); }