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