mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-29 13:58:51 +03:00
Add support for RSS feeds using magnet links (Closes #1016379)
This commit is contained in:
parent
39ea57fe29
commit
5a65580169
6 changed files with 50 additions and 19 deletions
|
@ -145,6 +145,7 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa
|
|||
connect(QBtSession::instance(), SIGNAL(finishedTorrent(QTorrentHandle)), this, SLOT(finishedTorrent(QTorrentHandle)));
|
||||
connect(QBtSession::instance(), SIGNAL(trackerAuthenticationRequired(QTorrentHandle)), this, SLOT(trackerAuthenticationRequired(QTorrentHandle)));
|
||||
connect(QBtSession::instance(), SIGNAL(newDownloadedTorrent(QString, QString)), this, SLOT(processDownloadedFiles(QString, QString)));
|
||||
connect(QBtSession::instance(), SIGNAL(newMagnetLink(QString)), this, SLOT(processNewMagnetLink(QString)));
|
||||
connect(QBtSession::instance(), SIGNAL(downloadFromUrlFailure(QString, QString)), this, SLOT(handleDownloadFromUrlFailure(QString, QString)));
|
||||
connect(QBtSession::instance(), SIGNAL(alternativeSpeedsModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool)));
|
||||
connect(QBtSession::instance(), SIGNAL(recursiveTorrentDownloadPossible(QTorrentHandle)), this, SLOT(askRecursiveTorrentDownloadConfirmation(QTorrentHandle)));
|
||||
|
@ -979,6 +980,16 @@ void MainWindow::processDownloadedFiles(QString path, QString url) {
|
|||
QBtSession::instance()->addTorrent(path, false, url);
|
||||
}
|
||||
|
||||
void MainWindow::processNewMagnetLink(const QString& link)
|
||||
{
|
||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||
const bool useTorrentAdditionDialog = settings.value(QString::fromUtf8("Preferences/Downloads/AdditionDialog"), true).toBool();
|
||||
if (useTorrentAdditionDialog)
|
||||
AddNewTorrentDialog::showMagnet(link);
|
||||
else
|
||||
QBtSession::instance()->addMagnetUri(link);
|
||||
}
|
||||
|
||||
void MainWindow::optionsSaved() {
|
||||
loadPreferences();
|
||||
}
|
||||
|
|
|
@ -129,6 +129,7 @@ protected slots:
|
|||
void addTorrent(QString path);
|
||||
void addUnauthenticatedTracker(const QPair<QTorrentHandle,QString> &tracker);
|
||||
void processDownloadedFiles(QString path, QString url);
|
||||
void processNewMagnetLink(const QString& link);
|
||||
void finishedTorrent(const QTorrentHandle& h) const;
|
||||
void askRecursiveTorrentDownloadConfirmation(const QTorrentHandle &h);
|
||||
// Options slots
|
||||
|
|
|
@ -2642,7 +2642,12 @@ void QBtSession::downloadFromURLList(const QStringList& urls) {
|
|||
}
|
||||
}
|
||||
|
||||
void QBtSession::addMagnetSkipAddDlg(QString uri) {
|
||||
void QBtSession::addMagnetInteractive(const QString& uri)
|
||||
{
|
||||
emit newMagnetLink(uri);
|
||||
}
|
||||
|
||||
void QBtSession::addMagnetSkipAddDlg(const QString& uri) {
|
||||
addMagnetUri(uri, false);
|
||||
}
|
||||
|
||||
|
|
|
@ -161,7 +161,8 @@ public slots:
|
|||
#endif
|
||||
void addPeerBanMessage(QString msg, bool from_ipfilter);
|
||||
void processDownloadedFile(QString, QString);
|
||||
void addMagnetSkipAddDlg(QString uri);
|
||||
void addMagnetSkipAddDlg(const QString& uri);
|
||||
void addMagnetInteractive(const QString& uri);
|
||||
void downloadFromURLList(const QStringList& urls);
|
||||
void configureSession();
|
||||
void banIP(QString ip);
|
||||
|
@ -202,6 +203,7 @@ signals:
|
|||
void trackerError(const QString &hash, QString time, QString msg);
|
||||
void trackerAuthenticationRequired(const QTorrentHandle& h);
|
||||
void newDownloadedTorrent(QString path, QString url);
|
||||
void newMagnetLink(const QString& link);
|
||||
void updateFileSize(const QString &hash);
|
||||
void downloadFromUrlFailure(QString url, QString reason);
|
||||
void torrentFinishedChecking(const QTorrentHandle& h);
|
||||
|
|
|
@ -326,23 +326,32 @@ void RSSImp::downloadTorrent() {
|
|||
foreach (const QListWidgetItem* item, selected_items) {
|
||||
RssArticlePtr article = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
|
||||
->getItem(item->data(Article::IdRole).toString());
|
||||
// Load possible cookies
|
||||
QList<QNetworkCookie> cookies;
|
||||
QString feed_url = m_feedList->getItemID(m_feedList->selectedItems().first());
|
||||
QString feed_hostname = QUrl::fromEncoded(feed_url.toUtf8()).host();
|
||||
const QList<QByteArray> raw_cookies = RssSettings().getHostNameCookies(feed_hostname);
|
||||
foreach (const QByteArray& raw_cookie, raw_cookies) {
|
||||
QList<QByteArray> cookie_parts = raw_cookie.split('=');
|
||||
if (cookie_parts.size() == 2) {
|
||||
qDebug("Loading cookie: %s = %s", cookie_parts.first().constData(), cookie_parts.last().constData());
|
||||
cookies << QNetworkCookie(cookie_parts.first(), cookie_parts.last());
|
||||
|
||||
QString torrentLink;
|
||||
if (article->hasAttachment())
|
||||
torrentLink = article->torrentUrl();
|
||||
else
|
||||
torrentLink = article->link();
|
||||
|
||||
// Check if it is a magnet link
|
||||
if (torrentLink.startsWith("magnet:", Qt::CaseInsensitive))
|
||||
QBtSession::instance()->addMagnetInteractive(torrentLink);
|
||||
else {
|
||||
// Load possible cookies
|
||||
QList<QNetworkCookie> cookies;
|
||||
QString feed_url = m_feedList->getItemID(m_feedList->selectedItems().first());
|
||||
QString feed_hostname = QUrl::fromEncoded(feed_url.toUtf8()).host();
|
||||
const QList<QByteArray> raw_cookies = RssSettings().getHostNameCookies(feed_hostname);
|
||||
foreach (const QByteArray& raw_cookie, raw_cookies) {
|
||||
QList<QByteArray> cookie_parts = raw_cookie.split('=');
|
||||
if (cookie_parts.size() == 2) {
|
||||
qDebug("Loading cookie: %s = %s", cookie_parts.first().constData(), cookie_parts.last().constData());
|
||||
cookies << QNetworkCookie(cookie_parts.first(), cookie_parts.last());
|
||||
}
|
||||
}
|
||||
}
|
||||
qDebug("Loaded %d cookies for RSS item\n", cookies.size());
|
||||
if (article->hasAttachment()) {
|
||||
QBtSession::instance()->downloadFromUrl(article->torrentUrl(), cookies);
|
||||
} else {
|
||||
QBtSession::instance()->downloadFromUrl(article->link(), cookies);
|
||||
qDebug("Loaded %d cookies for RSS item\n", cookies.size());
|
||||
|
||||
QBtSession::instance()->downloadFromUrl(torrentLink, cookies);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -295,7 +295,10 @@ void RssFeed::downloadMatchingArticleTorrents() {
|
|||
// Download the torrent
|
||||
QString torrent_url = article->hasAttachment() ? article->torrentUrl() : article->link();
|
||||
QBtSession::instance()->addConsoleMessage(tr("Automatically downloading %1 torrent from %2 RSS feed...").arg(article->title()).arg(displayName()));
|
||||
QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule->savePath(), matching_rule->label());
|
||||
if (torrent_url.startsWith("magnet:", Qt::CaseInsensitive))
|
||||
QBtSession::instance()->addMagnetSkipAddDlg(torrent_url);
|
||||
else
|
||||
QBtSession::instance()->downloadUrlAndSkipDialog(torrent_url, matching_rule->savePath(), matching_rule->label());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue