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); } }
const AudioFileModel AnalyzeTask::analyzeFile(const QString &filePath, int *type) { *type = fileTypeNormal; AudioFileModel audioFile(filePath); QFile readTest(filePath); if(!readTest.open(QIODevice::ReadOnly)) { *type = fileTypeDenied; return audioFile; } if(checkFile_CDDA(readTest)) { *type = fileTypeCDDA; return audioFile; } readTest.close(); bool skipNext = false; QPair<quint32, quint32> id_val(UINT_MAX, UINT_MAX); quint32 coverType = UINT_MAX; QByteArray coverData; QStringList params; params << QString("--Inform=file://%1").arg(QDir::toNativeSeparators(m_templateFile)); params << QDir::toNativeSeparators(filePath); QProcess process; MUtils::init_process(process, QFileInfo(m_mediaInfoBin).absolutePath()); process.start(m_mediaInfoBin, params); if(!process.waitForStarted()) { qWarning("MediaInfo process failed to create!"); qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData()); process.kill(); process.waitForFinished(-1); return audioFile; } 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("MediaInfo time out. Killing process and skipping file!"); process.kill(); process.waitForFinished(-1); return audioFile; } } QByteArray data; while(process.canReadLine()) { QString line = QString::fromUtf8(process.readLine().constData()).simplified(); if(!line.isEmpty()) { //qDebug("Line:%s", MUTILS_UTF8(line)); int index = line.indexOf('='); if(index > 0) { QString key = line.left(index).trimmed(); QString val = line.mid(index+1).trimmed(); if(!key.isEmpty()) { updateInfo(audioFile, skipNext, id_val, coverType, coverData, key, val); } } } } } if(audioFile.metaInfo().title().isEmpty()) { QString baseName = QFileInfo(filePath).fileName(); int index = baseName.lastIndexOf("."); if(index >= 0) { baseName = baseName.left(index); } baseName = baseName.replace("_", " ").simplified(); index = baseName.lastIndexOf(" - "); if(index >= 0) { baseName = baseName.mid(index + 3).trimmed(); } audioFile.metaInfo().setTitle(baseName); } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } if((coverType != UINT_MAX) && (!coverData.isEmpty())) { retrieveCover(audioFile, coverType, coverData); } if((audioFile.techInfo().audioType().compare("PCM", Qt::CaseInsensitive) == 0) && (audioFile.techInfo().audioProfile().compare("Float", Qt::CaseInsensitive) == 0)) { if(audioFile.techInfo().audioBitdepth() == 32) audioFile.techInfo().setAudioBitdepth(AudioFileModel::BITDEPTH_IEEE_FLOAT32); } return audioFile; }