Browse Source

Merge pull request #1941 from Gelmir/magnet_redirect

Work around magnet redirection in feeds
adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
0650d28da7
  1. 8
      src/downloadthread.cpp
  2. 1
      src/downloadthread.h
  3. 19
      src/qtlibtorrent/qbtsession.cpp
  4. 3
      src/qtlibtorrent/qbtsession.h

8
src/downloadthread.cpp

@ -121,6 +121,14 @@ void DownloadThread::processDlFinished(QNetworkReply* reply) { @@ -121,6 +121,14 @@ void DownloadThread::processDlFinished(QNetworkReply* reply) {
newUrl = reply->url().resolved(newUrl);
const QString newUrlString = newUrl.toString();
qDebug("Redirecting from %s to %s", qPrintable(url), qPrintable(newUrlString));
// Redirect to magnet workaround
if (newUrlString.startsWith("magnet:", Qt::CaseInsensitive)) {
qDebug("Magnet redirect detected.");
reply->abort();
emit magnetRedirect(newUrlString, url);
reply->deleteLater();
return;
}
m_redirectMapping.insert(newUrlString, url);
// redirecting with first cookies
downloadUrl(newUrlString, m_networkManager.cookieJar()->cookiesForUrl(url));

1
src/downloadthread.h

@ -54,6 +54,7 @@ public: @@ -54,6 +54,7 @@ public:
signals:
void downloadFinished(const QString &url, const QString &file_path);
void downloadFailure(const QString &url, const QString &reason);
void magnetRedirect(const QString &url_new, const QString &url_old);
private slots:
void processDlFinished(QNetworkReply* reply);

19
src/qtlibtorrent/qbtsession.cpp

@ -163,6 +163,7 @@ QBtSession::QBtSession() @@ -163,6 +163,7 @@ QBtSession::QBtSession()
downloader = new DownloadThread(this);
connect(downloader, SIGNAL(downloadFinished(QString, QString)), SLOT(processDownloadedFile(QString, QString)));
connect(downloader, SIGNAL(downloadFailure(QString, QString)), SLOT(handleDownloadFailure(QString, QString)));
connect(downloader, SIGNAL(magnetRedirect(QString, QString)), SLOT(handleMagnetRedirect(QString, QString)));
// Regular saving of fastresume data
connect(&resumeDataTimer, SIGNAL(timeout()), SLOT(saveTempFastResumeData()));
resumeDataTimer.start(170000); // 3min
@ -272,6 +273,20 @@ void QBtSession::handleDownloadFailure(QString url, QString reason) { @@ -272,6 +273,20 @@ void QBtSession::handleDownloadFailure(QString url, QString reason) {
savepathLabel_fromurl.remove(qurl);
}
void QBtSession::handleMagnetRedirect(const QString &url_new, const QString &url_old) {
if (url_skippingDlg.contains(url_old)) {
url_skippingDlg.removeOne(url_old);
QPair<QString, QString> savePath_label;
if (savepathLabel_fromurl.contains(url_old)) {
savePath_label = savepathLabel_fromurl.take(QUrl::fromEncoded(url_old.toUtf8()));
savepathLabel_fromurl.remove(url_old);
}
addMagnetSkipAddDlg(url_new, savePath_label.first, savePath_label.second, url_old);
}
else
addMagnetInteractive(url_new);
}
void QBtSession::setQueueingEnabled(bool enable) {
if (queueingEnabled != enable) {
qDebug("Queueing system is changing state...");
@ -2843,11 +2858,11 @@ void QBtSession::addMagnetInteractive(const QString& uri) @@ -2843,11 +2858,11 @@ void QBtSession::addMagnetInteractive(const QString& uri)
emit newMagnetLink(uri);
}
void QBtSession::addMagnetSkipAddDlg(const QString& uri, const QString& save_path, const QString& label) {
void QBtSession::addMagnetSkipAddDlg(const QString& uri, const QString& save_path, const QString& label, const QString &uri_old) {
if (!save_path.isEmpty() || !label.isEmpty())
savepathLabel_fromurl[uri] = qMakePair(fsutils::fromNativePath(save_path), label);
addMagnetUri(uri, false);
emit newDownloadedTorrentFromRss(uri);
emit newDownloadedTorrentFromRss(uri_old.isEmpty() ? uri : uri_old);
}
void QBtSession::downloadUrlAndSkipDialog(QString url, QString save_path, QString label, const QList<QNetworkCookie>& cookies) {

3
src/qtlibtorrent/qbtsession.h

@ -138,6 +138,7 @@ public slots: @@ -138,6 +138,7 @@ public slots:
void disableIPFilter();
void setQueueingEnabled(bool enable);
void handleDownloadFailure(QString url, QString reason);
void handleMagnetRedirect(const QString &url_new, const QString &url_old);
void downloadUrlAndSkipDialog(QString url, QString save_path=QString(), QString label=QString(), const QList<QNetworkCookie>& cookies = QList<QNetworkCookie>());
// Session configuration - Setters
void setListeningPort(int port);
@ -174,7 +175,7 @@ public slots: @@ -174,7 +175,7 @@ public slots:
void clearConsoleMessages() { consoleMessages.clear(); }
void clearPeerBanMessages() { peerBanMessages.clear(); }
void processDownloadedFile(QString, QString);
void addMagnetSkipAddDlg(const QString& uri, const QString& save_path = QString(), const QString& label = QString());
void addMagnetSkipAddDlg(const QString& uri, const QString& save_path = QString(), const QString& label = QString(), const QString &uri_old = QString());
void addMagnetInteractive(const QString& uri);
void downloadFromURLList(const QStringList& urls);
void configureSession();

Loading…
Cancel
Save