mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-12 07:48:04 +00:00
Improve detection of filename extension of audio/video files
This commit is contained in:
parent
529dd6e3a8
commit
e1f9083c81
@ -51,6 +51,7 @@
|
||||
#include <zlib.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QMimeDatabase>
|
||||
#include <QRegularExpression>
|
||||
#include <QSet>
|
||||
#include <QSysInfo>
|
||||
@ -62,6 +63,7 @@
|
||||
|
||||
#include "base/types.h"
|
||||
#include "base/unicodestrings.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/string.h"
|
||||
|
||||
namespace
|
||||
@ -290,9 +292,17 @@ qlonglong Utils::Misc::sizeInBytes(qreal size, const Utils::Misc::SizeUnit unit)
|
||||
return size;
|
||||
}
|
||||
|
||||
bool Utils::Misc::isPreviewable(const QString &extension)
|
||||
bool Utils::Misc::isPreviewable(const QString &filename)
|
||||
{
|
||||
static const QSet<QString> multimediaExtensions =
|
||||
const QString mime = QMimeDatabase().mimeTypeForFile(filename, QMimeDatabase::MatchExtension).name();
|
||||
|
||||
if (mime.startsWith(QLatin1String("audio"), Qt::CaseInsensitive)
|
||||
|| mime.startsWith(QLatin1String("video"), Qt::CaseInsensitive))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
const QSet<QString> multimediaExtensions =
|
||||
{
|
||||
"3GP",
|
||||
"AAC",
|
||||
@ -337,7 +347,7 @@ bool Utils::Misc::isPreviewable(const QString &extension)
|
||||
"WMA",
|
||||
"WMV"
|
||||
};
|
||||
return multimediaExtensions.contains(extension.toUpper());
|
||||
return multimediaExtensions.contains(Utils::Fs::fileExtension(filename).toUpper());
|
||||
}
|
||||
|
||||
QString Utils::Misc::userFriendlyDuration(const qlonglong seconds, const qlonglong maxCap)
|
||||
|
@ -77,7 +77,7 @@ namespace Utils::Misc
|
||||
int friendlyUnitPrecision(SizeUnit unit);
|
||||
qint64 sizeInBytes(qreal size, SizeUnit unit);
|
||||
|
||||
bool isPreviewable(const QString &extension);
|
||||
bool isPreviewable(const QString &filename);
|
||||
|
||||
// Take a number of seconds and return a user-friendly
|
||||
// time duration like "1d 2h 10m".
|
||||
|
@ -90,9 +90,8 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, const BitTorrent::Torr
|
||||
{
|
||||
QString fileName = torrent->fileName(i);
|
||||
if (fileName.endsWith(QB_EXT))
|
||||
fileName.chop(4);
|
||||
QString extension = Utils::Fs::fileExtension(fileName).toUpper();
|
||||
if (Utils::Misc::isPreviewable(extension))
|
||||
fileName.chop(QB_EXT.length());
|
||||
if (Utils::Misc::isPreviewable(fileName))
|
||||
{
|
||||
int row = m_previewListModel->rowCount();
|
||||
m_previewListModel->insertRow(row);
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include <QVector>
|
||||
#include <QWheelEvent>
|
||||
|
||||
#include "base/bittorrent/common.h"
|
||||
#include "base/bittorrent/infohash.h"
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "base/bittorrent/torrent.h"
|
||||
@ -93,7 +94,10 @@ namespace
|
||||
|
||||
for (int i = 0; i < torrent->filesCount(); ++i)
|
||||
{
|
||||
if (Utils::Misc::isPreviewable(Utils::Fs::fileExtension(torrent->fileName(i))))
|
||||
QString fileName = torrent->fileName(i);
|
||||
if (fileName.endsWith(QB_EXT))
|
||||
fileName.chop(QB_EXT.length());
|
||||
if (Utils::Misc::isPreviewable(fileName))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user