Browse Source

Use parse_magnet_uri() where possible.

adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
a8766058f3
  1. 34
      src/misc.cpp

34
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) {
const QUrl tracker = QUrl::fromEncoded(rx.cap(1).toUtf8()); if (ec)
qDebug() << Q_FUNC_INFO << "Found tracker: " << tracker.toString(); return trackers;
trackers << tracker;
pos += rx.matchedLength(); for (std::vector<std::string>::const_iterator i = p.trackers.begin(), e = p.trackers.end(); i != e; ++i)
} trackers.push_back(QUrl(toQStringU(*i)));
return trackers; return trackers;
} }

Loading…
Cancel
Save