///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
#include "Global.h"
#include "LockedFile.h"
#include "Model_AudioFile.h"
-#include "PlaylistImporter.h"
+#include "Thread_FileAnalyzer_Task.h"
#include <QDir>
#include <QFileInfo>
#include <QDate>
#include <QTime>
#include <QDebug>
-
-#include <math.h>
+#include <QImage>
+#include <QThreadPool>
+#include <QTime>
////////////////////////////////////////////////////////////
// Constructor
FileAnalyzer::FileAnalyzer(const QStringList &inputFiles)
:
+ m_abortFlag(false),
m_inputFiles(inputFiles),
- m_mediaInfoBin(lamexp_lookup_tool("mediainfo.exe")),
- m_avs2wavBin(lamexp_lookup_tool("avs2wav.exe")),
- m_abortFlag(false)
+ m_templateFile(NULL)
{
m_bSuccess = false;
m_bAborted = false;
-
- if(m_mediaInfoBin.isEmpty())
+}
+
+FileAnalyzer::~FileAnalyzer(void)
+{
+ if(m_templateFile)
{
- qFatal("Invalid path to MediaInfo binary. Tool not initialized properly.");
+ QString templatePath = m_templateFile->filePath();
+ LAMEXP_DELETE(m_templateFile);
+ if(QFile::exists(templatePath)) QFile::remove(templatePath);
}
-
- m_filesAccepted = 0;
- m_filesRejected = 0;
- m_filesDenied = 0;
- m_filesDummyCDDA = 0;
- m_filesCueSheet = 0;
+
+ AnalyzeTask::reset();
}
////////////////////////////////////////////////////////////
-// Thread Main
+// Static data
////////////////////////////////////////////////////////////
-void FileAnalyzer::run()
+const char *FileAnalyzer::g_tags_gen[] =
{
- m_bSuccess = false;
- m_bAborted = false;
-
- m_filesAccepted = 0;
- m_filesRejected = 0;
- m_filesDenied = 0;
- m_filesDummyCDDA = 0;
- m_filesCueSheet = 0;
-
- m_inputFiles.sort();
- m_recentlyAdded.clear();
- m_abortFlag = false;
-
- while(!m_inputFiles.isEmpty())
- {
- int fileType = fileTypeNormal;
- QString currentFile = QDir::fromNativeSeparators(m_inputFiles.takeFirst());
- qDebug("Analyzing: %s", currentFile.toUtf8().constData());
- emit fileSelected(QFileInfo(currentFile).fileName());
- AudioFileModel file = analyzeFile(currentFile, &fileType);
-
- if(m_abortFlag)
- {
- MessageBeep(MB_ICONERROR);
- m_bAborted = true;
- qWarning("Operation cancelled by user!");
- return;
- }
- if(fileType == fileTypeSkip)
- {
- qWarning("File was recently added, skipping!");
- continue;
- }
- if(fileType == fileTypeDenied)
- {
- m_filesDenied++;
- qWarning("Cannot access file for reading, skipping!");
- continue;
- }
- if(fileType == fileTypeCDDA)
- {
- m_filesDummyCDDA++;
- qWarning("Dummy CDDA file detected, skipping!");
- continue;
- }
-
- if(file.fileName().isEmpty() || file.formatContainerType().isEmpty() || file.formatAudioType().isEmpty())
- {
- if(PlaylistImporter::importPlaylist(m_inputFiles, currentFile))
- {
- qDebug("Imported playlist file.");
- }
- else if(!QFileInfo(currentFile).suffix().compare("cue", Qt::CaseInsensitive))
- {
- qWarning("Cue Sheet file detected, skipping!");
- m_filesCueSheet++;
- }
- else if(!QFileInfo(currentFile).suffix().compare("avs", Qt::CaseInsensitive))
- {
- qDebug("Found a potential Avisynth script, investigating...");
- if(analyzeAvisynthFile(currentFile, file))
- {
- m_filesAccepted++;
- emit fileAnalyzed(file);
- }
- else
- {
- qDebug("Rejected Avisynth file: %s", file.filePath().toUtf8().constData());
- m_filesRejected++;
- }
- }
- else
- {
- qDebug("Rejected file of unknown type: %s", file.filePath().toUtf8().constData());
- m_filesRejected++;
- }
- continue;
- }
-
- m_filesAccepted++;
- m_recentlyAdded.append(file.filePath());
- emit fileAnalyzed(file);
- }
-
- qDebug("All files added.\n");
- m_bSuccess = true;
-}
+ "ID",
+ "Format",
+ "Format_Profile",
+ "Format_Version",
+ "Duration",
+ "Title", "Track",
+ "Track/Position",
+ "Artist", "Performer",
+ "Album",
+ "Genre",
+ "Released_Date", "Recorded_Date",
+ "Comment",
+ "Cover",
+ "Cover_Type",
+ "Cover_Mime",
+ "Cover_Data",
+ NULL
+};
+
+const char *FileAnalyzer::g_tags_aud[] =
+{
+ "ID",
+ "Source",
+ "Format",
+ "Format_Profile",
+ "Format_Version",
+ "Channel(s)",
+ "SamplingRate",
+ "BitDepth",
+ "BitRate",
+ "BitRate_Mode",
+ "Encoded_Library",
+ NULL
+};
////////////////////////////////////////////////////////////
-// Privtae Functions
+// Thread Main
////////////////////////////////////////////////////////////
-const AudioFileModel FileAnalyzer::analyzeFile(const QString &filePath, int *type)
+void FileAnalyzer::run()
{
- *type = fileTypeNormal;
-
- AudioFileModel audioFile(filePath);
- m_currentSection = sectionOther;
- m_currentCover = coverNone;
-
- if(m_recentlyAdded.contains(filePath, Qt::CaseInsensitive))
- {
- *type = fileTypeSkip;
- return audioFile;
- }
+ m_abortFlag = false;
- QFile readTest(filePath);
- if(!readTest.open(QIODevice::ReadOnly))
- {
- *type = fileTypeDenied;
- return audioFile;
- }
-
- if(checkFile_CDDA(readTest))
- {
- *type = fileTypeCDDA;
- return audioFile;
- }
-
- readTest.close();
-
- QProcess process;
- process.setProcessChannelMode(QProcess::MergedChannels);
- process.setReadChannel(QProcess::StandardOutput);
- process.start(m_mediaInfoBin, QStringList() << QDir::toNativeSeparators(filePath));
-
- 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;
- }
+ m_bAborted = false;
+ m_bSuccess = 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("MediaInfo time out. Killing process and skipping file!");
- process.kill();
- process.waitForFinished(-1);
- return audioFile;
- }
- }
+ int nFiles = m_inputFiles.count();
- QByteArray data;
+ emit progressMaxChanged(nFiles);
+ emit progressValChanged(0);
- 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-1).trimmed();
- QString val = line.mid(index+1).trimmed();
- if(!key.isEmpty() && !val.isEmpty())
- {
- updateInfo(audioFile, key, val);
- }
- }
- else
- {
- updateSection(line);
- }
- }
- }
- }
+ m_inputFiles.sort();
- if(audioFile.fileName().isEmpty())
+ if(!m_templateFile)
{
- QString baseName = QFileInfo(filePath).fileName();
- int index = baseName.lastIndexOf(".");
-
- if(index >= 0)
+ if(!createTemplate())
{
- baseName = baseName.left(index);
- }
-
- baseName = baseName.replace("_", " ").simplified();
- index = baseName.lastIndexOf(" - ");
-
- if(index >= 0)
- {
- baseName = baseName.mid(index + 3).trimmed();
+ qWarning("Failed to create template file!");
+ return;
}
-
- audioFile.setFileName(baseName);
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
- {
- process.kill();
- process.waitForFinished(-1);
}
- if(m_currentCover != coverNone)
- {
- retrieveCover(audioFile, filePath);
- }
+ AnalyzeTask::reset();
+ QThreadPool *pool = new QThreadPool();
+ QThread::msleep(333);
- return audioFile;
-}
+ pool->setMaxThreadCount(qBound(2, ((QThread::idealThreadCount() * 3) / 2), 12));
-void FileAnalyzer::updateSection(const QString §ion)
-{
- if(section.startsWith("General", Qt::CaseInsensitive))
- {
- m_currentSection = sectionGeneral;
- }
- else if(!section.compare("Audio", Qt::CaseInsensitive) || section.startsWith("Audio #1", Qt::CaseInsensitive))
- {
- m_currentSection = sectionAudio;
- }
- else if(section.startsWith("Audio", Qt::CaseInsensitive) || section.startsWith("Video", Qt::CaseInsensitive) || section.startsWith("Text", Qt::CaseInsensitive) ||
- section.startsWith("Menu", Qt::CaseInsensitive) || section.startsWith("Image", Qt::CaseInsensitive) || section.startsWith("Chapters", Qt::CaseInsensitive))
- {
- m_currentSection = sectionOther;
- }
- else
- {
- m_currentSection = sectionOther;
- qWarning("Unknown section: %s", section.toUtf8().constData());
- }
-}
-
-void FileAnalyzer::updateInfo(AudioFileModel &audioFile, const QString &key, const QString &value)
-{
- switch(m_currentSection)
+ while(!(m_inputFiles.isEmpty() || m_bAborted))
{
- case sectionGeneral:
- if(!key.compare("Title", Qt::CaseInsensitive) || !key.compare("Track", Qt::CaseInsensitive) || !key.compare("Track Name", Qt::CaseInsensitive))
- {
- if(audioFile.fileName().isEmpty()) audioFile.setFileName(value);
- }
- else if(!key.compare("Duration", Qt::CaseInsensitive))
- {
- if(!audioFile.fileDuration()) audioFile.setFileDuration(parseDuration(value));
- }
- else if(!key.compare("Artist", Qt::CaseInsensitive) || !key.compare("Performer", Qt::CaseInsensitive))
- {
- if(audioFile.fileArtist().isEmpty()) audioFile.setFileArtist(value);
- }
- else if(!key.compare("Album", Qt::CaseInsensitive))
- {
- if(audioFile.fileAlbum().isEmpty()) audioFile.setFileAlbum(value);
- }
- else if(!key.compare("Genre", Qt::CaseInsensitive))
- {
- if(audioFile.fileGenre().isEmpty()) audioFile.setFileGenre(value);
- }
- else if(!key.compare("Year", Qt::CaseInsensitive) || !key.compare("Recorded Date", Qt::CaseInsensitive) || !key.compare("Encoded Date", Qt::CaseInsensitive))
- {
- if(!audioFile.fileYear()) audioFile.setFileYear(parseYear(value));
- }
- else if(!key.compare("Comment", Qt::CaseInsensitive))
- {
- if(audioFile.fileComment().isEmpty()) audioFile.setFileComment(value);
- }
- else if(!key.compare("Track Name/Position", Qt::CaseInsensitive))
- {
- if(!audioFile.filePosition()) audioFile.setFilePosition(value.toInt());
- }
- else if(!key.compare("Format", Qt::CaseInsensitive))
- {
- if(audioFile.formatContainerType().isEmpty()) audioFile.setFormatContainerType(value);
- }
- else if(!key.compare("Format Profile", Qt::CaseInsensitive))
- {
- if(audioFile.formatContainerProfile().isEmpty()) audioFile.setFormatContainerProfile(value);
- }
- else if(!key.compare("Cover", Qt::CaseInsensitive) || !key.compare("Cover type", Qt::CaseInsensitive))
- {
- if(m_currentCover == coverNone) m_currentCover = coverJpeg;
- }
- else if(!key.compare("Cover MIME", Qt::CaseInsensitive))
+ while(!(m_inputFiles.isEmpty() || m_bAborted))
{
- QString temp = value.split(" ", QString::SkipEmptyParts, Qt::CaseInsensitive).first();
- if(!temp.compare("image/jpeg", Qt::CaseInsensitive))
- {
- m_currentCover = coverJpeg;
- }
- else if(!temp.compare("image/png", Qt::CaseInsensitive))
- {
- m_currentCover = coverPng;
- }
- else if(!temp.compare("image/gif", Qt::CaseInsensitive))
+ if(!AnalyzeTask::waitForFreeSlot(&m_abortFlag))
{
- m_currentCover = coverGif;
+ qWarning("Timeout in AnalyzeTask::waitForFreeSlot() !!!");
}
- }
- break;
- case sectionAudio:
- if(!key.compare("Year", Qt::CaseInsensitive) || !key.compare("Recorded Date", Qt::CaseInsensitive) || !key.compare("Encoded Date", Qt::CaseInsensitive))
- {
- if(!audioFile.fileYear()) audioFile.setFileYear(parseYear(value));
- }
- else if(!key.compare("Format", Qt::CaseInsensitive))
- {
- if(audioFile.formatAudioType().isEmpty()) audioFile.setFormatAudioType(value);
- }
- else if(!key.compare("Format Profile", Qt::CaseInsensitive))
- {
- if(audioFile.formatAudioProfile().isEmpty()) audioFile.setFormatAudioProfile(value);
- }
- else if(!key.compare("Format Version", Qt::CaseInsensitive))
- {
- if(audioFile.formatAudioVersion().isEmpty()) audioFile.setFormatAudioVersion(value);
- }
- else if(!key.compare("Channel(s)", Qt::CaseInsensitive))
- {
- if(!audioFile.formatAudioChannels()) audioFile.setFormatAudioChannels(value.split(" ", QString::SkipEmptyParts).first().toUInt());
- }
- else if(!key.compare("Sampling rate", Qt::CaseInsensitive))
- {
- if(!audioFile.formatAudioSamplerate())
+ if(m_abortFlag)
{
- bool ok = false;
- float fTemp = abs(value.split(" ", QString::SkipEmptyParts).first().toFloat(&ok));
- if(ok) audioFile.setFormatAudioSamplerate(static_cast<unsigned int>(floor(fTemp * 1000.0f + 0.5f)));
+ MessageBeep(MB_ICONERROR);
+ m_bAborted = true;
+ break;
}
- }
- else if(!key.compare("Bit depth", Qt::CaseInsensitive))
- {
- if(!audioFile.formatAudioBitdepth()) audioFile.setFormatAudioBitdepth(value.split(" ", QString::SkipEmptyParts).first().toUInt());
- }
- else if(!key.compare("Duration", Qt::CaseInsensitive))
- {
- if(!audioFile.fileDuration()) audioFile.setFileDuration(parseDuration(value));
- }
- else if(!key.compare("Bit rate", Qt::CaseInsensitive))
- {
- if(!audioFile.formatAudioBitrate())
+
+ if(!m_bAborted)
{
- bool ok = false;
- unsigned int uiTemp = value.split(" ", QString::SkipEmptyParts).first().toUInt(&ok);
- if(ok)
- {
- audioFile.setFormatAudioBitrate(uiTemp);
- }
- else
+ const QString currentFile = QDir::fromNativeSeparators(m_inputFiles.takeFirst());
+
+ AnalyzeTask *task = new AnalyzeTask(currentFile, m_templateFile->filePath(), &m_abortFlag);
+ connect(task, SIGNAL(fileSelected(QString)), this, SIGNAL(fileSelected(QString)), Qt::DirectConnection);
+ connect(task, SIGNAL(progressValChanged(unsigned int)), this, SIGNAL(progressValChanged(unsigned int)), Qt::DirectConnection);
+ connect(task, SIGNAL(progressMaxChanged(unsigned int)), this, SIGNAL(progressMaxChanged(unsigned int)), Qt::DirectConnection);
+ connect(task, SIGNAL(fileAnalyzed(AudioFileModel)), this, SIGNAL(fileAnalyzed(AudioFileModel)), Qt::DirectConnection);
+
+ pool->start(task);
+
+ if(int count = AnalyzeTask::getAdditionalFiles(m_inputFiles))
{
- float fTemp = abs(value.split(" ", QString::SkipEmptyParts).first().toFloat(&ok));
- if(ok) audioFile.setFormatAudioBitrate(static_cast<unsigned int>(floor(fTemp + 0.5f)));
+ emit progressMaxChanged(nFiles += count);
}
}
}
- else if(!key.compare("Bit rate mode", Qt::CaseInsensitive))
+
+ //One of the Analyze tasks may have gathered additional files from a playlist!
+ if(!m_bAborted)
{
- if(audioFile.formatAudioBitrateMode() == AudioFileModel::BitrateModeUndefined)
+ pool->waitForDone();
+ if(int count = AnalyzeTask::getAdditionalFiles(m_inputFiles))
{
- if(!value.compare("Constant", Qt::CaseInsensitive)) audioFile.setFormatAudioBitrateMode(AudioFileModel::BitrateModeConstant);
- if(!value.compare("Variable", Qt::CaseInsensitive)) audioFile.setFormatAudioBitrateMode(AudioFileModel::BitrateModeVariable);
+ emit progressMaxChanged(nFiles += count);
}
}
- break;
- }
-}
-
-unsigned int FileAnalyzer::parseYear(const QString &str)
-{
- if(str.startsWith("UTC", Qt::CaseInsensitive))
- {
- QDate date = QDate::fromString(str.mid(3).trimmed().left(10), "yyyy-MM-dd");
- if(date.isValid())
- {
- return date.year();
- }
- else
- {
- return 0;
- }
- }
- else
- {
- bool ok = false;
- int year = str.toInt(&ok);
- if(ok && year > 0)
- {
- return year;
- }
- else
- {
- return 0;
- }
- }
-}
-
-unsigned int FileAnalyzer::parseDuration(const QString &str)
-{
- QTime time;
-
- time = QTime::fromString(str, "z'ms'");
- if(time.isValid())
- {
- return qMax(1, (time.hour() * 60 * 60) + (time.minute() * 60) + time.second());
- }
-
- time = QTime::fromString(str, "s's 'z'ms'");
- if(time.isValid())
- {
- return qMax(1, (time.hour() * 60 * 60) + (time.minute() * 60) + time.second());
- }
-
- time = QTime::fromString(str, "m'mn 's's'");
- if(time.isValid())
- {
- return qMax(1, (time.hour() * 60 * 60) + (time.minute() * 60) + time.second());
}
+
+ pool->waitForDone();
+ LAMEXP_DELETE(pool);
- time = QTime::fromString(str, "h'h 'm'mn'");
- if(time.isValid())
+ if(m_bAborted)
{
- return qMax(1, (time.hour() * 60 * 60) + (time.minute() * 60) + time.second());
+ qWarning("Operation cancelled by user!");
+ return;
}
-
- return 0;
-}
-
-bool FileAnalyzer::checkFile_CDDA(QFile &file)
-{
- file.reset();
- QByteArray data = file.read(128);
- int i = data.indexOf("RIFF");
- int j = data.indexOf("CDDA");
- int k = data.indexOf("fmt ");
-
- return ((i >= 0) && (j >= 0) && (k >= 0) && (k > j) && (j > i));
+ qDebug("All files added.\n");
+ m_bSuccess = true;
}
-void FileAnalyzer::retrieveCover(AudioFileModel &audioFile, const QString &filePath)
-{
- qDebug("Retrieving cover from: %s", filePath.toUtf8().constData());
- QString extension;
+////////////////////////////////////////////////////////////
+// Privtae Functions
+////////////////////////////////////////////////////////////
- switch(m_currentCover)
+bool FileAnalyzer::createTemplate(void)
+{
+ if(m_templateFile)
{
- case coverPng:
- extension = QString::fromLatin1("png");
- break;
- case coverGif:
- extension = QString::fromLatin1("gif");
- break;
- default:
- extension = QString::fromLatin1("jpg");
- break;
+ qWarning("Template file already exists!");
+ return true;
}
- QProcess process;
- process.setProcessChannelMode(QProcess::MergedChannels);
- process.setReadChannel(QProcess::StandardOutput);
- process.start(m_mediaInfoBin, QStringList() << "-f" << QDir::toNativeSeparators(filePath));
-
- if(!process.waitForStarted())
+ QString templatePath = QString("%1/%2.txt").arg(lamexp_temp_folder2(), lamexp_rand_str());
+
+ QFile templateFile(templatePath);
+ if(!templateFile.open(QIODevice::WriteOnly))
{
- qWarning("MediaInfo process failed to create!");
- qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
- process.kill();
- process.waitForFinished(-1);
- return;
+ return false;
}
- while(process.state() != QProcess::NotRunning)
+ templateFile.write("General;");
+ for(size_t i = 0; g_tags_gen[i]; i++)
{
- 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;
- }
- }
-
- 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-1).trimmed();
- QString val = line.mid(index+1).trimmed();
- if(!key.isEmpty() && !val.isEmpty())
- {
- if(!key.compare("Cover_Data", Qt::CaseInsensitive))
- {
- if(val.indexOf(" ") > 0)
- {
- val = val.split(" ", QString::SkipEmptyParts, Qt::CaseInsensitive).first();
- }
- QByteArray coverData = QByteArray::fromBase64(val.toLatin1());
- 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.setFileCover(coverFile.fileName(), true);
- }
- break;
- }
- }
- }
- }
- }
+ templateFile.write(QString("Gen_%1=%%1%\\n").arg(g_tags_gen[i]).toLatin1().constData());
}
+ templateFile.write("\\n\r\n");
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
+ templateFile.write("Audio;");
+ for(size_t i = 0; g_tags_aud[i]; i++)
{
- process.kill();
- process.waitForFinished(-1);
+ templateFile.write(QString("Aud_%1=%%1%\\n").arg(g_tags_aud[i]).toLatin1().constData());
}
-}
-
-bool FileAnalyzer::analyzeAvisynthFile(const QString &filePath, AudioFileModel &info)
-{
- QProcess process;
- process.setProcessChannelMode(QProcess::MergedChannels);
- process.setReadChannel(QProcess::StandardOutput);
- process.start(m_avs2wavBin, QStringList() << QDir::toNativeSeparators(filePath) << "?");
+ templateFile.write("\\n\r\n");
- if(!process.waitForStarted())
+ bool success = (templateFile.error() == QFile::NoError);
+ templateFile.close();
+
+ if(!success)
{
- qWarning("AVS2WAV process failed to create!");
- qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
- process.kill();
- process.waitForFinished(-1);
+ QFile::remove(templatePath);
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.setFileDuration(duration);
- }
- if(key.compare("SamplesPerSec", Qt::CaseInsensitive) == 0)
- {
- bool ok = false;
- unsigned int samplerate = val.toUInt(&ok);
- if(ok) info.setFormatAudioSamplerate (samplerate);
- }
- if(key.compare("Channels", Qt::CaseInsensitive) == 0)
- {
- bool ok = false;
- unsigned int channels = val.toUInt(&ok);
- if(ok) info.setFormatAudioChannels(channels);
- }
- if(key.compare("BitsPerSample", Qt::CaseInsensitive) == 0)
- {
- bool ok = false;
- unsigned int bitdepth = val.toUInt(&ok);
- if(ok) info.setFormatAudioBitdepth(bitdepth);
- }
- }
- }
- else
- {
- if(line.contains("[Audio Info]", Qt::CaseInsensitive))
- {
- info.setFormatAudioType("Avisynth");
- info.setFormatContainerType("Avisynth");
- bInfoHeaderFound = true;
- }
- }
- }
- }
- }
-
- process.waitForFinished();
- if(process.state() != QProcess::NotRunning)
+ try
{
- process.kill();
- process.waitForFinished(-1);
+ m_templateFile = new LockedFile(templatePath);
}
-
- //Check exit code
- switch(process.exitCode())
+ catch(...)
{
- 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?");
+ qWarning("Failed to lock template file!");
return false;
- break;
}
+
+ return true;
}
////////////////////////////////////////////////////////////
unsigned int FileAnalyzer::filesAccepted(void)
{
- return m_filesAccepted;
+ return AnalyzeTask::filesAccepted();
}
unsigned int FileAnalyzer::filesRejected(void)
{
- return m_filesRejected;
+ return AnalyzeTask::filesRejected();
}
unsigned int FileAnalyzer::filesDenied(void)
{
- return m_filesDenied;
+ return AnalyzeTask::filesDenied();
}
unsigned int FileAnalyzer::filesDummyCDDA(void)
{
- return m_filesDummyCDDA;
+ return AnalyzeTask::filesDummyCDDA();
}
unsigned int FileAnalyzer::filesCueSheet(void)
{
- return m_filesCueSheet;
+ return AnalyzeTask::filesCueSheet();
}
////////////////////////////////////////////////////////////