mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
parent
5a4b3b25d3
commit
8d0870c953
5 changed files with 24 additions and 27 deletions
|
@ -204,7 +204,7 @@ bool RequestParser::parseRequestLine(const QString &line)
|
||||||
m_request.method = match.captured(1);
|
m_request.method = match.captured(1);
|
||||||
|
|
||||||
// Request Target
|
// Request Target
|
||||||
const QByteArray url {match.captured(2).toLatin1()};
|
const QByteArray url {match.capturedView(2).toLatin1()};
|
||||||
const int sepPos = url.indexOf('?');
|
const int sepPos = url.indexOf('?');
|
||||||
const QByteArrayView pathComponent = ((sepPos == -1) ? url : QByteArrayView(url).first(sepPos));
|
const QByteArrayView pathComponent = ((sepPos == -1) ? url : QByteArrayView(url).first(sepPos));
|
||||||
|
|
||||||
|
|
|
@ -96,9 +96,9 @@ void DNSUpdater::ipRequestFinished(const DownloadResult &result)
|
||||||
const QRegularExpressionMatch ipRegexMatch = QRegularExpression(u"Current IP Address:\\s+([^<]+)</body>"_s).match(QString::fromUtf8(result.data));
|
const QRegularExpressionMatch ipRegexMatch = QRegularExpression(u"Current IP Address:\\s+([^<]+)</body>"_s).match(QString::fromUtf8(result.data));
|
||||||
if (ipRegexMatch.hasMatch())
|
if (ipRegexMatch.hasMatch())
|
||||||
{
|
{
|
||||||
QString ipStr = ipRegexMatch.captured(1);
|
const QString ipStr = ipRegexMatch.captured(1);
|
||||||
qDebug() << Q_FUNC_INFO << "Regular expression captured the following IP:" << ipStr;
|
qDebug() << Q_FUNC_INFO << "Regular expression captured the following IP:" << ipStr;
|
||||||
QHostAddress newIp(ipStr);
|
const QHostAddress newIp {ipStr};
|
||||||
if (!newIp.isNull())
|
if (!newIp.isNull())
|
||||||
{
|
{
|
||||||
if (m_lastIP != newIp)
|
if (m_lastIP != newIp)
|
||||||
|
|
|
@ -184,14 +184,10 @@ QString computeEpisodeName(const QString &article)
|
||||||
for (int i = 1; i <= match.lastCapturedIndex(); ++i)
|
for (int i = 1; i <= match.lastCapturedIndex(); ++i)
|
||||||
{
|
{
|
||||||
const QString cap = match.captured(i);
|
const QString cap = match.captured(i);
|
||||||
|
|
||||||
if (cap.isEmpty())
|
if (cap.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool isInt = false;
|
ret.append(cap);
|
||||||
const int x = cap.toInt(&isInt);
|
|
||||||
|
|
||||||
ret.append(isInt ? QString::number(x) : cap);
|
|
||||||
}
|
}
|
||||||
return ret.join(u'x');
|
return ret.join(u'x');
|
||||||
}
|
}
|
||||||
|
@ -293,11 +289,11 @@ bool AutoDownloadRule::matchesEpisodeFilterExpression(const QString &articleTitl
|
||||||
if (!matcher.hasMatch())
|
if (!matcher.hasMatch())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QString season {matcher.captured(1)};
|
const QStringView season {matcher.capturedView(1)};
|
||||||
const QStringList episodes {matcher.captured(2).split(u';')};
|
const QList<QStringView> episodes {matcher.capturedView(2).split(u';')};
|
||||||
const int seasonOurs {season.toInt()};
|
const int seasonOurs {season.toInt()};
|
||||||
|
|
||||||
for (QString episode : episodes)
|
for (QStringView episode : episodes)
|
||||||
{
|
{
|
||||||
if (episode.isEmpty())
|
if (episode.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
@ -308,11 +304,11 @@ bool AutoDownloadRule::matchesEpisodeFilterExpression(const QString &articleTitl
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
||||||
episode.slice(1);
|
episode.slice(1);
|
||||||
#else
|
#else
|
||||||
episode.remove(0, 1);
|
episode = episode.sliced(1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (episode.indexOf(u'-') != -1)
|
if (episode.contains(u'-'))
|
||||||
{ // Range detected
|
{ // Range detected
|
||||||
const QString partialPattern1 {u"\\bs0?(\\d{1,4})[ -_\\.]?e(0?\\d{1,4})(?:\\D|\\b)"_s};
|
const QString partialPattern1 {u"\\bs0?(\\d{1,4})[ -_\\.]?e(0?\\d{1,4})(?:\\D|\\b)"_s};
|
||||||
const QString partialPattern2 {u"\\b(\\d{1,4})x(0?\\d{1,4})(?:\\D|\\b)"_s};
|
const QString partialPattern2 {u"\\b(\\d{1,4})x(0?\\d{1,4})(?:\\D|\\b)"_s};
|
||||||
|
@ -329,8 +325,8 @@ bool AutoDownloadRule::matchesEpisodeFilterExpression(const QString &articleTitl
|
||||||
|
|
||||||
if (matched)
|
if (matched)
|
||||||
{
|
{
|
||||||
const int seasonTheirs {matcher.captured(1).toInt()};
|
const int seasonTheirs {matcher.capturedView(1).toInt()};
|
||||||
const int episodeTheirs {matcher.captured(2).toInt()};
|
const int episodeTheirs {matcher.capturedView(2).toInt()};
|
||||||
|
|
||||||
if (episode.endsWith(u'-'))
|
if (episode.endsWith(u'-'))
|
||||||
{ // Infinite range
|
{ // Infinite range
|
||||||
|
@ -340,13 +336,14 @@ bool AutoDownloadRule::matchesEpisodeFilterExpression(const QString &articleTitl
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Normal range
|
{ // Normal range
|
||||||
const QStringList range {episode.split(u'-')};
|
const QList<QStringView> range {episode.split(u'-')};
|
||||||
Q_ASSERT(range.size() == 2);
|
Q_ASSERT(range.size() == 2);
|
||||||
if (range.first().toInt() > range.last().toInt())
|
|
||||||
continue; // Ignore this subrule completely
|
|
||||||
|
|
||||||
const int episodeOursFirst {range.first().toInt()};
|
const int episodeOursFirst {range.first().toInt()};
|
||||||
const int episodeOursLast {range.last().toInt()};
|
const int episodeOursLast {range.last().toInt()};
|
||||||
|
if (episodeOursFirst > episodeOursLast)
|
||||||
|
continue; // Ignore this subrule completely
|
||||||
|
|
||||||
if ((seasonTheirs == seasonOurs) && ((episodeOursFirst <= episodeTheirs) && (episodeOursLast >= episodeTheirs)))
|
if ((seasonTheirs == seasonOurs) && ((episodeOursFirst <= episodeTheirs) && (episodeOursLast >= episodeTheirs)))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,8 +69,8 @@ namespace
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
const QRegularExpressionMatch match = iter.next();
|
const QRegularExpressionMatch match = iter.next();
|
||||||
const QString scheme = match.captured(4);
|
const QStringView scheme = match.capturedView(4);
|
||||||
const QString host = match.captured(5);
|
const QStringView host = match.capturedView(5);
|
||||||
if (!scheme.isEmpty())
|
if (!scheme.isEmpty())
|
||||||
{
|
{
|
||||||
if (host.isEmpty())
|
if (host.isEmpty())
|
||||||
|
@ -80,21 +80,21 @@ namespace
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString relativePath = match.captured(6);
|
QStringView relativePath = match.capturedView(6);
|
||||||
if (relativePath.startsWith(u'/'))
|
if (relativePath.startsWith(u'/'))
|
||||||
{
|
{
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
||||||
relativePath.slice(1);
|
relativePath.slice(1);
|
||||||
#else
|
#else
|
||||||
relativePath.remove(0, 1);
|
relativePath = relativePath.sliced(1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString absoluteUrl = !host.isEmpty()
|
const QString absoluteUrl = !host.isEmpty()
|
||||||
? QString(defaultScheme + u':' + host) : (normalizedBaseUrl + relativePath);
|
? QString(defaultScheme + u':' + host) : (normalizedBaseUrl + relativePath);
|
||||||
const QString fullMatch = match.captured(0);
|
const QString fullMatch = match.captured(0);
|
||||||
const QString prefix = match.captured(1);
|
const QStringView prefix = match.capturedView(1);
|
||||||
const QString suffix = match.captured(7);
|
const QStringView suffix = match.capturedView(7);
|
||||||
|
|
||||||
html.replace(fullMatch, (prefix + absoluteUrl + suffix));
|
html.replace(fullMatch, (prefix + absoluteUrl + suffix));
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,15 +237,15 @@ void WebApplication::translateDocument(QString &data) const
|
||||||
i = data.indexOf(regex, i, ®exMatch);
|
i = data.indexOf(regex, i, ®exMatch);
|
||||||
if (i >= 0)
|
if (i >= 0)
|
||||||
{
|
{
|
||||||
const QString sourceText = regexMatch.captured(1);
|
const QStringView sourceText = regexMatch.capturedView(1);
|
||||||
const QString context = regexMatch.captured(3);
|
const QStringView context = regexMatch.capturedView(3);
|
||||||
|
|
||||||
const QString loadedText = m_translationFileLoaded
|
const QString loadedText = m_translationFileLoaded
|
||||||
? m_translator.translate(context.toUtf8().constData(), sourceText.toUtf8().constData())
|
? m_translator.translate(context.toUtf8().constData(), sourceText.toUtf8().constData())
|
||||||
: QString();
|
: QString();
|
||||||
// `loadedText` is empty when translation is not provided
|
// `loadedText` is empty when translation is not provided
|
||||||
// it should fallback to `sourceText`
|
// it should fallback to `sourceText`
|
||||||
QString translation = loadedText.isEmpty() ? sourceText : loadedText;
|
QString translation = loadedText.isEmpty() ? sourceText.toString() : loadedText;
|
||||||
|
|
||||||
// Escape quotes to workaround issues with HTML attributes
|
// Escape quotes to workaround issues with HTML attributes
|
||||||
// FIXME: this is a dirty workaround to deal with broken translation strings:
|
// FIXME: this is a dirty workaround to deal with broken translation strings:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue