mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 04:54:18 +00:00
RSS: Better cookies support
This commit is contained in:
parent
716e84264e
commit
d55f3b5aff
@ -32,7 +32,6 @@
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkProxy>
|
||||
#include <QNetworkCookie>
|
||||
#include <QNetworkCookieJar>
|
||||
|
||||
#include "downloadthread.h"
|
||||
@ -109,39 +108,21 @@ void DownloadThread::processDlFinished(QNetworkReply* reply) {
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
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) {
|
||||
void DownloadThread::downloadTorrentUrl(const QString &url, const QList<QNetworkCookie>& cookies)
|
||||
{
|
||||
// Process request
|
||||
QNetworkReply *reply = downloadUrl(url);
|
||||
QNetworkReply *reply = downloadUrl(url, cookies);
|
||||
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
|
||||
applyProxySettings();
|
||||
#ifndef DISABLE_GUI
|
||||
// Load cookies
|
||||
QString host_name = QUrl::fromEncoded(url.toUtf8()).host();
|
||||
if (!host_name.isEmpty())
|
||||
loadCookies(host_name, url);
|
||||
#endif
|
||||
// Set cookies
|
||||
if (!cookies.empty()) {
|
||||
qDebug("Setting %d cookies for url: %s", cookies.size(), qPrintable(url));
|
||||
m_networkManager.cookieJar()->setCookiesFromUrl(cookies, url);
|
||||
}
|
||||
// Process download request
|
||||
qDebug("url is %s", qPrintable(url));
|
||||
const QUrl qurl = QUrl::fromEncoded(url.toUtf8());
|
||||
|
@ -32,6 +32,7 @@
|
||||
#define DOWNLOADTHREAD_H
|
||||
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkCookie>
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
#include <QSslError>
|
||||
@ -45,8 +46,8 @@ class DownloadThread : public QObject {
|
||||
|
||||
public:
|
||||
DownloadThread(QObject* parent = 0);
|
||||
QNetworkReply* downloadUrl(const QString &url);
|
||||
void downloadTorrentUrl(const QString &url);
|
||||
QNetworkReply* downloadUrl(const QString &url, const QList<QNetworkCookie>& raw_cookies = QList<QNetworkCookie>());
|
||||
void downloadTorrentUrl(const QString &url, const QList<QNetworkCookie>& raw_cookies = QList<QNetworkCookie>());
|
||||
//void setProxy(QString IP, int port, QString username, QString password);
|
||||
|
||||
signals:
|
||||
@ -63,9 +64,6 @@ private slots:
|
||||
private:
|
||||
QString errorCodeToString(QNetworkReply::NetworkError status);
|
||||
void applyProxySettings();
|
||||
#ifndef DISABLE_GUI
|
||||
void loadCookies(const QString &host_name, QString url);
|
||||
#endif
|
||||
|
||||
private:
|
||||
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,
|
||||
// download the torrent file to a tmp location, then
|
||||
// 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)
|
||||
#ifndef DISABLE_GUI
|
||||
, QPalette::WindowText
|
||||
@ -2621,7 +2622,7 @@ void QBtSession::downloadFromUrl(const QString &url) {
|
||||
);
|
||||
//emit aboutToDownloadFromUrl(url);
|
||||
// Launch downloader thread
|
||||
downloader->downloadTorrentUrl(url);
|
||||
downloader->downloadTorrentUrl(url, cookies);
|
||||
}
|
||||
|
||||
void QBtSession::downloadFromURLList(const QStringList& urls) {
|
||||
|
@ -41,6 +41,7 @@
|
||||
#endif
|
||||
#include <QPointer>
|
||||
#include <QTimer>
|
||||
#include <QNetworkCookie>
|
||||
|
||||
#include <libtorrent/version.hpp>
|
||||
#include <libtorrent/session.hpp>
|
||||
@ -107,7 +108,7 @@ public slots:
|
||||
QTorrentHandle addMagnetUri(QString magnet_uri, bool resumed=false);
|
||||
void loadSessionState();
|
||||
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 startUpTorrents();
|
||||
void recheckTorrent(const QString &hash);
|
||||
|
@ -124,13 +124,14 @@ void RSSImp::on_actionManage_cookies_triggered() {
|
||||
Q_ASSERT(!m_feedList->selectedItems().empty());
|
||||
// Get feed hostname
|
||||
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));
|
||||
Q_ASSERT(!feed_hostname.isEmpty());
|
||||
bool ok = false;
|
||||
RssSettings settings;
|
||||
QList<QByteArray> raw_cookies = CookiesDlg::askForCookies(this, settings.getHostNameCookies(feed_hostname), &ok);
|
||||
if (ok) {
|
||||
qDebug() << "Settings cookies for host name: " << feed_hostname;
|
||||
settings.setHostNameCookies(feed_hostname, raw_cookies);
|
||||
}
|
||||
}
|
||||
@ -325,10 +326,23 @@ 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());
|
||||
}
|
||||
}
|
||||
qDebug("Loaded %d cookies for RSS item\n", cookies.size());
|
||||
if (article->hasAttachment()) {
|
||||
QBtSession::instance()->downloadFromUrl(article->torrentUrl());
|
||||
QBtSession::instance()->downloadFromUrl(article->torrentUrl(), cookies);
|
||||
} else {
|
||||
QBtSession::instance()->downloadFromUrl(article->link());
|
||||
QBtSession::instance()->downloadFromUrl(article->link(), cookies);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user