mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-02 18:04:32 +00:00
Use parse_magnet_uri() where possible.
This commit is contained in:
parent
f413e8b121
commit
a8766058f3
32
src/misc.cpp
32
src/misc.cpp
@ -382,29 +382,27 @@ QString misc::bcLinkToMagnet(QString bc_link)
|
|||||||
|
|
||||||
QString misc::magnetUriToName(const QString& magnet_uri)
|
QString misc::magnetUriToName(const QString& magnet_uri)
|
||||||
{
|
{
|
||||||
QString name = "";
|
add_torrent_params p;
|
||||||
QRegExp regHex("dn=([^&]+)");
|
error_code ec;
|
||||||
const int pos = regHex.indexIn(magnet_uri);
|
parse_magnet_uri(magnet_uri.toUtf8().constData(), p, ec);
|
||||||
if (pos > -1) {
|
|
||||||
const QString found = regHex.cap(1);
|
if (ec)
|
||||||
// URL decode
|
return QString::null;
|
||||||
name = QUrl::fromPercentEncoding(found.toLocal8Bit()).replace("+", " ");
|
return toQStringU(p.name);
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QUrl> misc::magnetUriToTrackers(const QString& magnet_uri)
|
QList<QUrl> misc::magnetUriToTrackers(const QString& magnet_uri)
|
||||||
{
|
{
|
||||||
QList<QUrl> trackers;
|
QList<QUrl> trackers;
|
||||||
QRegExp rx("tr=([^&]+)");
|
add_torrent_params p;
|
||||||
int pos = 0;
|
error_code ec;
|
||||||
|
parse_magnet_uri(magnet_uri.toUtf8().constData(), p, ec);
|
||||||
|
|
||||||
while ((pos = rx.indexIn(magnet_uri, pos)) != -1) {
|
if (ec)
|
||||||
const QUrl tracker = QUrl::fromEncoded(rx.cap(1).toUtf8());
|
return trackers;
|
||||||
qDebug() << Q_FUNC_INFO << "Found tracker: " << tracker.toString();
|
|
||||||
trackers << tracker;
|
for (std::vector<std::string>::const_iterator i = p.trackers.begin(), e = p.trackers.end(); i != e; ++i)
|
||||||
pos += rx.matchedLength();
|
trackers.push_back(QUrl(toQStringU(*i)));
|
||||||
}
|
|
||||||
|
|
||||||
return trackers;
|
return trackers;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user