mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-02 09:55:55 +00:00
Fix cookie support for RSS feeds (closes #119)
This commit is contained in:
parent
8758be5912
commit
6cf2f942e7
@ -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:
|
||||||
|
@ -347,19 +347,10 @@ void RSSImp::downloadSelectedTorrents()
|
|||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,12 @@ void RssFeed::addArticle(const RssArticlePtr& article)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QNetworkCookie> RssFeed::feedCookies() const
|
||||||
|
{
|
||||||
|
QString feed_hostname = QUrl::fromEncoded(m_url.toUtf8()).host();
|
||||||
|
return RssSettings().getHostNameQNetworkCookies(feed_hostname);
|
||||||
|
}
|
||||||
|
|
||||||
bool RssFeed::refresh()
|
bool RssFeed::refresh()
|
||||||
{
|
{
|
||||||
if (m_loading) {
|
if (m_loading) {
|
||||||
@ -144,7 +150,7 @@ bool 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());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QVariantHash>
|
#include <QVariantHash>
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
|
#include <QNetworkCookie>
|
||||||
|
|
||||||
#include "rssfile.h"
|
#include "rssfile.h"
|
||||||
|
|
||||||
@ -90,6 +91,7 @@ private:
|
|||||||
void loadItemsFromDisk();
|
void loadItemsFromDisk();
|
||||||
void addArticle(const RssArticlePtr& article);
|
void addArticle(const RssArticlePtr& article);
|
||||||
void downloadArticleTorrentIfMatching(RssDownloadRuleList* rules, const RssArticlePtr& article);
|
void downloadArticleTorrentIfMatching(RssDownloadRuleList* rules, const RssArticlePtr& article);
|
||||||
|
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…
x
Reference in New Issue
Block a user