mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-26 16:15:10 -07:00
Fix cookie support for RSS feeds (closes #119)
This commit is contained in:
parent
7bfd0e058b
commit
90a2021948
5 changed files with 26 additions and 13 deletions
|
@ -46,8 +46,8 @@ class DownloadThread : public QObject {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DownloadThread(QObject* parent = 0);
|
DownloadThread(QObject* parent = 0);
|
||||||
QNetworkReply* downloadUrl(const QString &url, const QList<QNetworkCookie>& raw_cookies = QList<QNetworkCookie>());
|
QNetworkReply* downloadUrl(const QString &url, const QList<QNetworkCookie>& cookies = QList<QNetworkCookie>());
|
||||||
void downloadTorrentUrl(const QString &url, const QList<QNetworkCookie>& raw_cookies = QList<QNetworkCookie>());
|
void downloadTorrentUrl(const QString &url, const QList<QNetworkCookie>& 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:
|
||||||
|
|
|
@ -338,19 +338,10 @@ void RSSImp::downloadTorrent() {
|
||||||
QBtSession::instance()->addMagnetInteractive(torrentLink);
|
QBtSession::instance()->addMagnetInteractive(torrentLink);
|
||||||
else {
|
else {
|
||||||
// Load possible cookies
|
// Load possible cookies
|
||||||
QList<QNetworkCookie> cookies;
|
|
||||||
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.toUtf8()).host();
|
QString feed_hostname = QUrl::fromEncoded(feed_url.toUtf8()).host();
|
||||||
const QList<QByteArray> raw_cookies = RssSettings().getHostNameCookies(feed_hostname);
|
QList<QNetworkCookie> cookies = RssSettings().getHostNameQNetworkCookies(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());
|
qDebug("Loaded %d cookies for RSS item\n", cookies.size());
|
||||||
|
|
||||||
QBtSession::instance()->downloadFromUrl(torrentLink, cookies);
|
QBtSession::instance()->downloadFromUrl(torrentLink, cookies);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,12 @@ void RssFeed::loadItemsFromDisk() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QNetworkCookie> RssFeed::feedCookies() const
|
||||||
|
{
|
||||||
|
QString feed_hostname = QUrl::fromEncoded(m_url.toUtf8()).host();
|
||||||
|
return RssSettings().getHostNameQNetworkCookies(feed_hostname);
|
||||||
|
}
|
||||||
|
|
||||||
void RssFeed::refresh() {
|
void RssFeed::refresh() {
|
||||||
if (m_loading) {
|
if (m_loading) {
|
||||||
qWarning() << Q_FUNC_INFO << "Feed" << this->displayName() << "is already being refreshed, ignoring request";
|
qWarning() << Q_FUNC_INFO << "Feed" << this->displayName() << "is already being refreshed, ignoring request";
|
||||||
|
@ -101,7 +107,7 @@ void RssFeed::refresh() {
|
||||||
}
|
}
|
||||||
m_loading = true;
|
m_loading = true;
|
||||||
// Download the RSS again
|
// Download the RSS again
|
||||||
m_manager->rssDownloader()->downloadUrl(m_url);
|
m_manager->rssDownloader()->downloadUrl(m_url, feedCookies());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RssFeed::removeAllSettings() {
|
void RssFeed::removeAllSettings() {
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
|
#include <QNetworkCookie>
|
||||||
|
|
||||||
#include "rssfile.h"
|
#include "rssfile.h"
|
||||||
|
|
||||||
|
@ -85,6 +86,7 @@ private:
|
||||||
void downloadMatchingArticleTorrents();
|
void downloadMatchingArticleTorrents();
|
||||||
QString iconUrl() const;
|
QString iconUrl() const;
|
||||||
void loadItemsFromDisk();
|
void loadItemsFromDisk();
|
||||||
|
QList<QNetworkCookie> feedCookies() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RssManager* m_manager;
|
RssManager* m_manager;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#define RSSSETTINGS_H
|
#define RSSSETTINGS_H
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QNetworkCookie>
|
||||||
#include "qinisettings.h"
|
#include "qinisettings.h"
|
||||||
|
|
||||||
class RssSettings: public QIniSettings{
|
class RssSettings: public QIniSettings{
|
||||||
|
@ -94,6 +95,19 @@ public:
|
||||||
return raw_cookies.split(':');
|
return raw_cookies.split(':');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QNetworkCookie> getHostNameQNetworkCookies(const QString& host_name) const {
|
||||||
|
QList<QNetworkCookie> cookies;
|
||||||
|
const QList<QByteArray> raw_cookies = getHostNameCookies(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 = %s", cookie_parts.first().constData(), cookie_parts.last().constData());
|
||||||
|
cookies << QNetworkCookie(cookie_parts.first(), cookie_parts.last());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cookies;
|
||||||
|
}
|
||||||
|
|
||||||
void setHostNameCookies(const QString &host_name, const QList<QByteArray> &cookies) {
|
void setHostNameCookies(const QString &host_name, const QList<QByteArray> &cookies) {
|
||||||
QMap<QString, QVariant> hosts_table = value("Rss/hosts_cookies").toMap();
|
QMap<QString, QVariant> hosts_table = value("Rss/hosts_cookies").toMap();
|
||||||
QByteArray raw_cookies = "";
|
QByteArray raw_cookies = "";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue