aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/General/converter/converter.cpp2
-rw-r--r--src/plugins/General/rgscan/rgscanner.cpp2
-rw-r--r--src/plugins/Input/cue/cueparser.cpp4
-rw-r--r--src/plugins/Input/cue/decoder_cue.cpp2
-rw-r--r--src/plugins/Input/flac/cueparser.cpp4
-rw-r--r--src/plugins/Input/wavpack/cueparser.cpp4
-rw-r--r--src/qmmp/decoder.cpp65
-rw-r--r--src/qmmp/decoder.h3
-rw-r--r--src/qmmp/metadatamanager.cpp6
-rw-r--r--src/qmmp/qmmpaudioengine.cpp2
10 files changed, 60 insertions, 34 deletions
diff --git a/src/plugins/General/converter/converter.cpp b/src/plugins/General/converter/converter.cpp
index 702a0aae2..cf6f8947e 100644
--- a/src/plugins/General/converter/converter.cpp
+++ b/src/plugins/General/converter/converter.cpp
@@ -82,7 +82,7 @@ bool Converter::prepare(const QString &url, int row, const QVariantMap &preset)
DecoderFactory *factory = 0;
if(!source->url().contains("://"))
- factory = Decoder::findByPath(source->url());
+ factory = Decoder::findByFilePath(source->url());
if(!factory)
factory = Decoder::findByMime(source->contentType());
if(!factory && source->ioDevice() && source->url().contains("://")) //ignore content of local files
diff --git a/src/plugins/General/rgscan/rgscanner.cpp b/src/plugins/General/rgscan/rgscanner.cpp
index 2c50c9fd7..7d1c085a8 100644
--- a/src/plugins/General/rgscan/rgscanner.cpp
+++ b/src/plugins/General/rgscan/rgscanner.cpp
@@ -74,7 +74,7 @@ bool RGScanner::prepare(const QString &url)
return false;
}
- DecoderFactory *factory = Decoder::findByPath(source->url());
+ DecoderFactory *factory = Decoder::findByFilePath(source->url());
if(!factory)
{
diff --git a/src/plugins/Input/cue/cueparser.cpp b/src/plugins/Input/cue/cueparser.cpp
index 7383e4111..893d0627f 100644
--- a/src/plugins/Input/cue/cueparser.cpp
+++ b/src/plugins/Input/cue/cueparser.cpp
@@ -307,7 +307,7 @@ qint64 CUEParser::getLength(const QString &str)
QString CUEParser::getDirtyPath(const QString &cue_path, const QString &path)
{
- if((QFile::exists(path) && Decoder::findByPath(path)) || !m_dirty)
+ if((QFile::exists(path) && Decoder::findByFilePath(path)) || !m_dirty)
return path;
QStringList candidates;
@@ -316,7 +316,7 @@ QString CUEParser::getDirtyPath(const QString &cue_path, const QString &path)
{
it.next();
QString f = it.filePath();
- if ((f != cue_path) && Decoder::findByPath(f))
+ if ((f != cue_path) && Decoder::findByFilePath(f))
candidates.push_back(f);
}
diff --git a/src/plugins/Input/cue/decoder_cue.cpp b/src/plugins/Input/cue/decoder_cue.cpp
index 141317fb4..29853ea2a 100644
--- a/src/plugins/Input/cue/decoder_cue.cpp
+++ b/src/plugins/Input/cue/decoder_cue.cpp
@@ -71,7 +71,7 @@ bool DecoderCUE::initialize()
qWarning("DecoderCUE: file \"%s\" doesn't exist", qPrintable(m_path));
return false;
}
- DecoderFactory *df = Decoder::findByPath(m_path);
+ DecoderFactory *df = Decoder::findByFilePath(m_path);
if (!df)
{
qWarning("DecoderCUE: unsupported file format");
diff --git a/src/plugins/Input/flac/cueparser.cpp b/src/plugins/Input/flac/cueparser.cpp
index 8933a4ff9..4736d6326 100644
--- a/src/plugins/Input/flac/cueparser.cpp
+++ b/src/plugins/Input/flac/cueparser.cpp
@@ -216,7 +216,7 @@ qint64 CUEParser::getLength(const QString &str)
QString CUEParser::getDirtyPath(const QString &cue, const QString &path)
{
- if (Decoder::findByPath(path) || ! m_dirty)
+ if (Decoder::findByFilePath(path) || ! m_dirty)
return path;
QStringList candidates;
@@ -225,7 +225,7 @@ QString CUEParser::getDirtyPath(const QString &cue, const QString &path)
{
it.next();
QString f = it.filePath();
- if ((f != cue) && Decoder::findByPath(f))
+ if ((f != cue) && Decoder::findByFilePath(f))
candidates.push_back(f);
}
diff --git a/src/plugins/Input/wavpack/cueparser.cpp b/src/plugins/Input/wavpack/cueparser.cpp
index a8a176eb4..0554370c6 100644
--- a/src/plugins/Input/wavpack/cueparser.cpp
+++ b/src/plugins/Input/wavpack/cueparser.cpp
@@ -216,7 +216,7 @@ qint64 CUEParser::getLength(const QString &str)
QString CUEParser::getDirtyPath(const QString &cue, const QString &path)
{
- if (Decoder::findByPath(path) || ! m_dirty)
+ if (Decoder::findByFilePath(path) || ! m_dirty)
return path;
QStringList candidates;
@@ -225,7 +225,7 @@ QString CUEParser::getDirtyPath(const QString &cue, const QString &path)
{
it.next();
QString f = it.filePath();
- if ((f != cue) && Decoder::findByPath(f))
+ if ((f != cue) && Decoder::findByFilePath(f))
candidates.push_back(f);
}
diff --git a/src/qmmp/decoder.cpp b/src/qmmp/decoder.cpp
index 89327edc2..d2b84c1bd 100644
--- a/src/qmmp/decoder.cpp
+++ b/src/qmmp/decoder.cpp
@@ -84,7 +84,6 @@ QMap<Qmmp::MetaData, QString> Decoder::takeMetaData()
// static methods
QStringList Decoder::m_disabledNames;
-DecoderFactory *Decoder::m_lastFactory = 0;
QList<QmmpPluginCache*> *Decoder::m_cache = 0;
//sort cache items by priority
@@ -146,13 +145,13 @@ QStringList Decoder::protocols()
return protocolsList;
}
-DecoderFactory *Decoder::findByPath(const QString& source, bool useContent)
+DecoderFactory *Decoder::findByFilePath(const QString &path, bool useContent)
{
loadPlugins();
- DecoderFactory *fact = m_lastFactory;
+ DecoderFactory *fact = 0;
if(useContent)
{
- QFile file(source);
+ QFile file(path);
if(!file.open(QIODevice::ReadOnly))
{
qWarning("Decoder: file open error: %s", qPrintable(file.errorString()));
@@ -181,28 +180,56 @@ DecoderFactory *Decoder::findByPath(const QString& source, bool useContent)
continue;
if (fact->canDecode(&buffer))
- {
- m_lastFactory = fact;
return fact;
- }
}
- fact = 0;
+ return 0;
}
- if (fact && isEnabled(fact) && fact->supports(source)) //try last factory
- return fact;
-
- foreach (QmmpPluginCache *item, *m_cache)
+ else
{
- if(m_disabledNames.contains(item->shortName()))
- continue;
- DecoderFactory *fact = item->decoderFactory();
- if(fact && fact->supports(source))
+ QList<DecoderFactory*> filered;
+ foreach (QmmpPluginCache *item, *m_cache)
{
- m_lastFactory = fact;
- return fact;
+ if(m_disabledNames.contains(item->shortName()))
+ continue;
+
+ DecoderFactory *fact = item->decoderFactory();
+
+ foreach(QString filter, fact->properties().filters)
+ {
+ QRegExp regexp(filter, Qt::CaseInsensitive, QRegExp::Wildcard);
+ if (regexp.exactMatch(path))
+ {
+ filered.append(fact);
+ break;
+ }
+ }
}
+
+ if(filered.isEmpty())
+ return 0;
+
+ if(filered.size() == 1)
+ return filered.at(0);
+
+ //more than one factories with same filters
+ //try to determine by content
+ QFile file(path);
+ if(!file.open(QIODevice::ReadOnly))
+ {
+ qWarning("Decoder: file open error: %s", qPrintable(file.errorString()));
+ return 0;
+ }
+ QByteArray array = file.read(8192);
+ QBuffer buffer(&array);
+ buffer.open(QIODevice::ReadOnly);
+
+ foreach (fact, filered)
+ {
+ if(fact->canDecode(&buffer))
+ return fact;
+ }
+ return 0;
}
- return 0;
}
DecoderFactory *Decoder::findByMime(const QString& type)
diff --git a/src/qmmp/decoder.h b/src/qmmp/decoder.h
index 4585ee65a..340722b06 100644
--- a/src/qmmp/decoder.h
+++ b/src/qmmp/decoder.h
@@ -111,7 +111,7 @@ public:
* @param path Full local file path.
* @param useContent Content-based file type determination (\b true - enabled, \b false - disabled)
*/
- static DecoderFactory *findByPath(const QString &path, bool useContent = false);
+ static DecoderFactory *findByFilePath(const QString &path, bool useContent = false);
/*!
* Returns DecoderFactory pointer which supports mime type \b mime or \b 0 if mime type \b mime is unsupported
*/
@@ -173,7 +173,6 @@ protected:
private:
static void loadPlugins();
- static DecoderFactory *m_lastFactory;
static QList<QmmpPluginCache*> *m_cache;
static QStringList m_disabledNames;
AudioParameters m_parameters;
diff --git a/src/qmmp/metadatamanager.cpp b/src/qmmp/metadatamanager.cpp
index 14e9aa07b..dea21ad5e 100644
--- a/src/qmmp/metadatamanager.cpp
+++ b/src/qmmp/metadatamanager.cpp
@@ -58,7 +58,7 @@ QList <FileInfo *> MetaDataManager::createPlayList(const QString &fileName, bool
{
if(!QFile::exists(fileName))
return list;
- else if((fact = Decoder::findByPath(fileName, m_settings->determineFileTypeByContent())))
+ else if((fact = Decoder::findByFilePath(fileName, m_settings->determineFileTypeByContent())))
return fact->createPlayList(fileName, useMetaData, ignoredPaths);
else if((efact = AbstractEngine::findByPath(fileName)))
return efact->createPlayList(fileName, useMetaData, ignoredPaths);
@@ -90,7 +90,7 @@ MetaDataModel* MetaDataManager::createMetaDataModel(const QString &path, QObject
{
if(!QFile::exists(path))
return 0;
- else if((fact = Decoder::findByPath(path, m_settings->determineFileTypeByContent())))
+ else if((fact = Decoder::findByFilePath(path, m_settings->determineFileTypeByContent())))
return fact->createMetaDataModel(path, parent);
else if((efact = AbstractEngine::findByPath(path)))
return efact->createMetaDataModel(path, parent);
@@ -168,7 +168,7 @@ bool MetaDataManager::supports(const QString &fileName) const
{
if (!QFile::exists(fileName))
return false;
- if((fact = Decoder::findByPath(fileName)))
+ if((fact = Decoder::findByFilePath(fileName)))
return true;
else if((efact = AbstractEngine::findByPath(fileName)))
return true;
diff --git a/src/qmmp/qmmpaudioengine.cpp b/src/qmmp/qmmpaudioengine.cpp
index 6f79a7ca6..72491f116 100644
--- a/src/qmmp/qmmpaudioengine.cpp
+++ b/src/qmmp/qmmpaudioengine.cpp
@@ -132,7 +132,7 @@ bool QmmpAudioEngine::enqueue(InputSource *source)
DecoderFactory *factory = 0;
if(!factory && !source->url().contains("://"))
- factory = Decoder::findByPath(source->url(), m_settings->determineFileTypeByContent());
+ factory = Decoder::findByFilePath(source->url(), m_settings->determineFileTypeByContent());
if(!factory)
factory = Decoder::findByMime(source->contentType());
if(!factory && source->ioDevice() && source->url().contains("://")) //ignore content of local files