diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/qmmp/decoder.cpp | 47 | ||||
| -rw-r--r-- | src/qmmp/decoder.h | 6 | ||||
| -rw-r--r-- | src/qmmp/metadatamanager.cpp | 7 | ||||
| -rw-r--r-- | src/qmmp/qmmpaudioengine.cpp | 4 |
4 files changed, 56 insertions, 8 deletions
diff --git a/src/qmmp/decoder.cpp b/src/qmmp/decoder.cpp index 7d22a9ca3..a20f64b8b 100644 --- a/src/qmmp/decoder.cpp +++ b/src/qmmp/decoder.cpp @@ -166,10 +166,38 @@ QStringList Decoder::protocols() return protocolsList; } -DecoderFactory *Decoder::findByPath(const QString& source) +DecoderFactory *Decoder::findByPath(const QString& source, bool useContent) { checkFactories(); DecoderFactory *fact = m_lastFactory; + if(useContent) + { + QFile file(source); + 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); + + //try last factory with stream based input or local files support + if (fact && isEnabled(fact) && (!fact->properties().noInput || + fact->properties().protocols.contains("file"))) + return fact; + + foreach(DecoderFactory *fact, *m_factories) + { + if(fact->properties().noInput && !fact->properties().protocols.contains("file")) + continue; + + if (isEnabled(fact) && fact->canDecode(&buffer)) + { + return fact; + } + } + } if (fact && fact->supports(source) && isEnabled(fact)) //try last factory return fact; foreach(fact, *m_factories) @@ -197,12 +225,27 @@ DecoderFactory *Decoder::findByMime(const QString& type) return 0; } +/*DecoderFactory *Decoder::findByContent(const QString &path) +{ + checkFactories(); + 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); + return findByContent(&buffer); +}*/ + DecoderFactory *Decoder::findByContent(QIODevice *input) { checkFactories(); foreach(DecoderFactory *fact, *m_factories) { - if (isEnabled(fact) && fact->canDecode(input)) + if (isEnabled(fact) && !fact->properties().noInput && fact->canDecode(input)) { return fact; } diff --git a/src/qmmp/decoder.h b/src/qmmp/decoder.h index 59d547c98..cc0b2d4ee 100644 --- a/src/qmmp/decoder.h +++ b/src/qmmp/decoder.h @@ -108,14 +108,16 @@ public: QMap<Qmmp::MetaData, QString> takeMetaData(); /*! * Returns DecoderFactory pointer which supports file \b path or 0 if file \b path is unsupported + * @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); + static DecoderFactory *findByPath(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 */ static DecoderFactory *findByMime(const QString &mime); /*! - * Returns DecoderFactory pointer which supports data provided by QIODevice \b input + * Returns DecoderFactory pointer which supports data provided by \b input * or \b 0 if data is unsupported. */ static DecoderFactory *findByContent(QIODevice *input); diff --git a/src/qmmp/metadatamanager.cpp b/src/qmmp/metadatamanager.cpp index e79b65b68..2e2d834eb 100644 --- a/src/qmmp/metadatamanager.cpp +++ b/src/qmmp/metadatamanager.cpp @@ -20,6 +20,7 @@ #include <QFile> #include <QFileInfo> +#include <QBuffer> #include <QMutexLocker> #include "decoder.h" #include "decoderfactory.h" @@ -54,7 +55,7 @@ QList <FileInfo *> MetaDataManager::createPlayList(const QString &fileName, bool { if(!QFile::exists(fileName)) return list; - if((fact = Decoder::findByPath(fileName))) + else if((fact = Decoder::findByPath(fileName, m_settings->determineFileTypeByContent()))) return fact->createPlayList(fileName, useMetaData); else if((efact = AbstractEngine::findByPath(fileName))) return efact->createPlayList(fileName, useMetaData); @@ -86,7 +87,7 @@ MetaDataModel* MetaDataManager::createMetaDataModel(const QString &path, QObject { if(!QFile::exists(path)) return 0; - if((fact = Decoder::findByPath(path))) + else if((fact = Decoder::findByPath(path, m_settings->determineFileTypeByContent()))) return fact->createMetaDataModel(path, parent); else if((efact = AbstractEngine::findByPath(path))) return efact->createMetaDataModel(path, parent); @@ -140,6 +141,8 @@ QStringList MetaDataManager::nameFilters() const if (AbstractEngine::isEnabled(fact)) filters << fact->properties().filters; } + if(m_settings->determineFileTypeByContent()) + filters << "*"; return filters; } diff --git a/src/qmmp/qmmpaudioengine.cpp b/src/qmmp/qmmpaudioengine.cpp index 271442a7e..68c9de5f9 100644 --- a/src/qmmp/qmmpaudioengine.cpp +++ b/src/qmmp/qmmpaudioengine.cpp @@ -105,8 +105,8 @@ bool QmmpAudioEngine::enqueue(InputSource *source) DecoderFactory *factory = 0; - if(!source->url().contains("://")) - factory = Decoder::findByPath(source->url()); + if(!factory && !source->url().contains("://")) + factory = Decoder::findByPath(source->url(), m_settings->determineFileTypeByContent()); if(!factory) factory = Decoder::findByMime(source->contentType()); if(!factory && source->ioDevice() && source->url().contains("://")) //ignore content of local files |
