mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-02 09:55:55 +00:00
RSS: Better cookies support
This commit is contained in:
parent
716e84264e
commit
d55f3b5aff
@ -32,7 +32,6 @@
|
|||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QNetworkProxy>
|
#include <QNetworkProxy>
|
||||||
#include <QNetworkCookie>
|
|
||||||
#include <QNetworkCookieJar>
|
#include <QNetworkCookieJar>
|
||||||
|
|
||||||
#include "downloadthread.h"
|
#include "downloadthread.h"
|
||||||
@ -109,39 +108,21 @@ void DownloadThread::processDlFinished(QNetworkReply* reply) {
|
|||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DISABLE_GUI
|
void DownloadThread::downloadTorrentUrl(const QString &url, const QList<QNetworkCookie>& cookies)
|
||||||
void DownloadThread::loadCookies(const QString &host_name, QString url) {
|
{
|
||||||
const QList<QByteArray> raw_cookies = RssSettings().getHostNameCookies(host_name);
|
|
||||||
QNetworkCookieJar *cookie_jar = m_networkManager.cookieJar();
|
|
||||||
QList<QNetworkCookie> cookies;
|
|
||||||
qDebug("Loading cookies for host name: %s", qPrintable(host_name));
|
|
||||||
foreach (const QByteArray& raw_cookie, raw_cookies) {
|
|
||||||
QList<QByteArray> cookie_parts = raw_cookie.split('=');
|
|
||||||
if (cookie_parts.size() == 2) {
|
|
||||||
qDebug("Loading cookie: %s", raw_cookie.constData());
|
|
||||||
cookies << QNetworkCookie(cookie_parts.first(), cookie_parts.last());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cookie_jar->setCookiesFromUrl(cookies, url);
|
|
||||||
m_networkManager.setCookieJar(cookie_jar);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void DownloadThread::downloadTorrentUrl(const QString &url) {
|
|
||||||
// Process request
|
// Process request
|
||||||
QNetworkReply *reply = downloadUrl(url);
|
QNetworkReply *reply = downloadUrl(url, cookies);
|
||||||
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(checkDownloadSize(qint64,qint64)));
|
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(checkDownloadSize(qint64,qint64)));
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReply* DownloadThread::downloadUrl(const QString &url) {
|
QNetworkReply* DownloadThread::downloadUrl(const QString &url, const QList<QNetworkCookie>& cookies) {
|
||||||
// Update proxy settings
|
// Update proxy settings
|
||||||
applyProxySettings();
|
applyProxySettings();
|
||||||
#ifndef DISABLE_GUI
|
// Set cookies
|
||||||
// Load cookies
|
if (!cookies.empty()) {
|
||||||
QString host_name = QUrl::fromEncoded(url.toUtf8()).host();
|
qDebug("Setting %d cookies for url: %s", cookies.size(), qPrintable(url));
|
||||||
if (!host_name.isEmpty())
|
m_networkManager.cookieJar()->setCookiesFromUrl(cookies, url);
|
||||||
loadCookies(host_name, url);
|
}
|
||||||
#endif
|
|
||||||
// Process download request
|
// Process download request
|
||||||
qDebug("url is %s", qPrintable(url));
|
qDebug("url is %s", qPrintable(url));
|
||||||
const QUrl qurl = QUrl::fromEncoded(url.toUtf8());
|
const QUrl qurl = QUrl::fromEncoded(url.toUtf8());
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#define DOWNLOADTHREAD_H
|
#define DOWNLOADTHREAD_H
|
||||||
|
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkCookie>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QSslError>
|
#include <QSslError>
|
||||||
@ -45,8 +46,8 @@ class DownloadThread : public QObject {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
DownloadThread(QObject* parent = 0);
|
DownloadThread(QObject* parent = 0);
|
||||||
QNetworkReply* downloadUrl(const QString &url);
|
QNetworkReply* downloadUrl(const QString &url, const QList<QNetworkCookie>& raw_cookies = QList<QNetworkCookie>());
|
||||||
void downloadTorrentUrl(const QString &url);
|
void downloadTorrentUrl(const QString &url, const QList<QNetworkCookie>& raw_cookies = QList<QNetworkCookie>());
|
||||||
//void setProxy(QString IP, int port, QString username, QString password);
|
//void setProxy(QString IP, int port, QString username, QString password);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@ -63,9 +64,6 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QString errorCodeToString(QNetworkReply::NetworkError status);
|
QString errorCodeToString(QNetworkReply::NetworkError status);
|
||||||
void applyProxySettings();
|
void applyProxySettings();
|
||||||
#ifndef DISABLE_GUI
|
|
||||||
void loadCookies(const QString &host_name, QString url);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager m_networkManager;
|
QNetworkAccessManager m_networkManager;
|
||||||
|
@ -2613,7 +2613,8 @@ QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString f
|
|||||||
// Take an url string to a torrent file,
|
// Take an url string to a torrent file,
|
||||||
// download the torrent file to a tmp location, then
|
// download the torrent file to a tmp location, then
|
||||||
// add it to download list
|
// add it to download list
|
||||||
void QBtSession::downloadFromUrl(const QString &url) {
|
void QBtSession::downloadFromUrl(const QString &url, const QList<QNetworkCookie>& cookies)
|
||||||
|
{
|
||||||
addConsoleMessage(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(url)
|
addConsoleMessage(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(url)
|
||||||
#ifndef DISABLE_GUI
|
#ifndef DISABLE_GUI
|
||||||
, QPalette::WindowText
|
, QPalette::WindowText
|
||||||
@ -2621,7 +2622,7 @@ void QBtSession::downloadFromUrl(const QString &url) {
|
|||||||
);
|
);
|
||||||
//emit aboutToDownloadFromUrl(url);
|
//emit aboutToDownloadFromUrl(url);
|
||||||
// Launch downloader thread
|
// Launch downloader thread
|
||||||
downloader->downloadTorrentUrl(url);
|
downloader->downloadTorrentUrl(url, cookies);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QBtSession::downloadFromURLList(const QStringList& urls) {
|
void QBtSession::downloadFromURLList(const QStringList& urls) {
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QNetworkCookie>
|
||||||
|
|
||||||
#include <libtorrent/version.hpp>
|
#include <libtorrent/version.hpp>
|
||||||
#include <libtorrent/session.hpp>
|
#include <libtorrent/session.hpp>
|
||||||
@ -107,7 +108,7 @@ public slots:
|
|||||||
QTorrentHandle addMagnetUri(QString magnet_uri, bool resumed=false);
|
QTorrentHandle addMagnetUri(QString magnet_uri, bool resumed=false);
|
||||||
void loadSessionState();
|
void loadSessionState();
|
||||||
void saveSessionState();
|
void saveSessionState();
|
||||||
void downloadFromUrl(const QString &url);
|
void downloadFromUrl(const QString &url, const QList<QNetworkCookie>& cookies = QList<QNetworkCookie>());
|
||||||
void deleteTorrent(const QString &hash, bool delete_local_files = false);
|
void deleteTorrent(const QString &hash, bool delete_local_files = false);
|
||||||
void startUpTorrents();
|
void startUpTorrents();
|
||||||
void recheckTorrent(const QString &hash);
|
void recheckTorrent(const QString &hash);
|
||||||
|
@ -124,13 +124,14 @@ void RSSImp::on_actionManage_cookies_triggered() {
|
|||||||
Q_ASSERT(!m_feedList->selectedItems().empty());
|
Q_ASSERT(!m_feedList->selectedItems().empty());
|
||||||
// Get feed hostname
|
// Get feed hostname
|
||||||
QString feed_url = m_feedList->getItemID(m_feedList->selectedItems().first());
|
QString feed_url = m_feedList->getItemID(m_feedList->selectedItems().first());
|
||||||
QString feed_hostname = QUrl::fromEncoded(feed_url.toLocal8Bit()).host();
|
QString feed_hostname = QUrl::fromEncoded(feed_url.toUtf8()).host();
|
||||||
qDebug("RSS Feed hostname is: %s", qPrintable(feed_hostname));
|
qDebug("RSS Feed hostname is: %s", qPrintable(feed_hostname));
|
||||||
Q_ASSERT(!feed_hostname.isEmpty());
|
Q_ASSERT(!feed_hostname.isEmpty());
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
RssSettings settings;
|
RssSettings settings;
|
||||||
QList<QByteArray> raw_cookies = CookiesDlg::askForCookies(this, settings.getHostNameCookies(feed_hostname), &ok);
|
QList<QByteArray> raw_cookies = CookiesDlg::askForCookies(this, settings.getHostNameCookies(feed_hostname), &ok);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
|
qDebug() << "Settings cookies for host name: " << feed_hostname;
|
||||||
settings.setHostNameCookies(feed_hostname, raw_cookies);
|
settings.setHostNameCookies(feed_hostname, raw_cookies);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -325,10 +326,23 @@ void RSSImp::downloadTorrent() {
|
|||||||
foreach (const QListWidgetItem* item, selected_items) {
|
foreach (const QListWidgetItem* item, selected_items) {
|
||||||
RssArticlePtr article = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
|
RssArticlePtr article = m_feedList->getRSSItemFromUrl(item->data(Article::FeedUrlRole).toString())
|
||||||
->getItem(item->data(Article::IdRole).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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug("Loaded %d cookies for RSS item\n", cookies.size());
|
||||||
if (article->hasAttachment()) {
|
if (article->hasAttachment()) {
|
||||||
QBtSession::instance()->downloadFromUrl(article->torrentUrl());
|
QBtSession::instance()->downloadFromUrl(article->torrentUrl(), cookies);
|
||||||
} else {
|
} else {
|
||||||
QBtSession::instance()->downloadFromUrl(article->link());
|
QBtSession::instance()->downloadFromUrl(article->link(), cookies);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user