mirror of
https://github.com/transmission/transmission
synced 2025-01-30 19:03:04 +00:00
Scrape www subdomain for favicon (#1451)
* fix: scrape other subdomains for favicon
This commit is contained in:
parent
017fa1cf1e
commit
92fc42ceb5
2 changed files with 49 additions and 9 deletions
|
@ -6,6 +6,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
#include <QDir>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
|
@ -160,12 +163,49 @@ FaviconCache::Key FaviconCache::add(QString const& url_str)
|
|||
{
|
||||
markUrlAsScraped(url_str);
|
||||
|
||||
auto const path = QStringLiteral("http://%1/favicon.").arg(url.host());
|
||||
nam_->get(QNetworkRequest(path + QStringLiteral("gif")));
|
||||
nam_->get(QNetworkRequest(path + QStringLiteral("ico")));
|
||||
nam_->get(QNetworkRequest(path + QStringLiteral("jpg")));
|
||||
nam_->get(QNetworkRequest(path + QStringLiteral("png")));
|
||||
nam_->get(QNetworkRequest(path + QStringLiteral("svg")));
|
||||
auto const scrape = [this](auto const host)
|
||||
{
|
||||
auto const schemes = std::array<QString, 2>{
|
||||
QStringLiteral("http"),
|
||||
QStringLiteral("https")
|
||||
};
|
||||
auto const suffixes = std::array<QString, 5>{
|
||||
QStringLiteral("gif"),
|
||||
QStringLiteral("ico"),
|
||||
QStringLiteral("jpg"),
|
||||
QStringLiteral("png"),
|
||||
QStringLiteral("svg")
|
||||
};
|
||||
for (auto const& scheme : schemes)
|
||||
{
|
||||
for (auto const& suffix : suffixes)
|
||||
{
|
||||
auto const path = QStringLiteral("%1://%2/favicon.%3").arg(scheme).arg(host).arg(suffix);
|
||||
nam_->get(QNetworkRequest(path));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// tracker.domain.com
|
||||
auto host = url.host();
|
||||
scrape(host);
|
||||
|
||||
auto const delim = QStringLiteral(".");
|
||||
auto const has_subdomain = host.count(delim) > 1;
|
||||
if (has_subdomain)
|
||||
{
|
||||
auto const original_subdomain = host.left(host.indexOf(delim));
|
||||
host.remove(0, original_subdomain.size() + 1);
|
||||
// domain.com
|
||||
scrape(host);
|
||||
|
||||
auto const www = QStringLiteral("www");
|
||||
if (original_subdomain != www)
|
||||
{
|
||||
// www.domain.com
|
||||
scrape(QStringLiteral("%1.%2").arg(www).arg(host));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return key;
|
||||
|
|
|
@ -520,7 +520,7 @@ void Session::torrentRenamePath(torrent_ids_t const& ids, QString const& oldpath
|
|||
tr(R"(<p><b>Unable to rename "%1" as "%2": %3.</b></p><p>Please correct the errors and try again.</p>)").
|
||||
arg(path).arg(name).arg(r.result), QMessageBox::Close,
|
||||
qApp->activeWindow());
|
||||
QObject::connect(d, &QMessageBox::rejected, d, &QMessageBox::deleteLater);
|
||||
d->connect(d, &QMessageBox::rejected, d, &QMessageBox::deleteLater);
|
||||
d->show();
|
||||
});
|
||||
|
||||
|
@ -1095,7 +1095,7 @@ void Session::addTorrent(AddData const& add_me, tr_variant* args, bool trash_ori
|
|||
auto* d = new QMessageBox(QMessageBox::Warning, tr("Error Adding Torrent"),
|
||||
QStringLiteral("<p><b>%1</b></p><p>%2</p>").arg(r.result).arg(add_me.readableName()), QMessageBox::Close,
|
||||
qApp->activeWindow());
|
||||
QObject::connect(d, &QMessageBox::rejected, d, &QMessageBox::deleteLater);
|
||||
d->connect(d, &QMessageBox::rejected, d, &QMessageBox::deleteLater);
|
||||
d->show();
|
||||
});
|
||||
|
||||
|
@ -1167,7 +1167,7 @@ void Session::onDuplicatesTimer()
|
|||
d->setDetailedText(detail);
|
||||
}
|
||||
|
||||
QObject::connect(d, &QMessageBox::rejected, d, &QMessageBox::deleteLater);
|
||||
d->connect(d, &QMessageBox::rejected, d, &QMessageBox::deleteLater);
|
||||
d->show();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue