Merge pull request #10757 from glassez/backport

Backport to v4.1.x
This commit is contained in:
Vladimir Golovnev 2019-06-04 17:59:10 +03:00 committed by GitHub
commit ad7b8a9bfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 17 deletions

View file

@ -2155,6 +2155,9 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne
try {
handle.auto_managed(false);
// Preloaded torrent is in "Upload mode" so we need to disable it
// otherwise the torrent never be downloaded (until application restart)
handle.set_upload_mode(false);
handle.pause();
}
catch (std::exception &) {}

View file

@ -585,6 +585,7 @@ void Parser::parse_impl(const QByteArray &feedData)
emit finished(m_result);
m_result.articles.clear(); // clear articles only
m_articleIDs.clear();
}
void Parser::parseRssArticle(QXmlStreamReader &xml)
@ -637,7 +638,7 @@ void Parser::parseRssArticle(QXmlStreamReader &xml)
if (article[Article::KeyTorrentURL].toString().isEmpty())
article[Article::KeyTorrentURL] = altTorrentUrl;
m_result.articles.prepend(article);
addArticle(article);
}
void Parser::parseRSSChannel(QXmlStreamReader &xml)
@ -732,7 +733,7 @@ void Parser::parseAtomArticle(QXmlStreamReader &xml)
}
}
m_result.articles.prepend(article);
addArticle(article);
}
void Parser::parseAtomChannel(QXmlStreamReader &xml)
@ -762,3 +763,34 @@ void Parser::parseAtomChannel(QXmlStreamReader &xml)
}
}
}
void Parser::addArticle(QVariantHash article)
{
QVariant &torrentURL = article[Article::KeyTorrentURL];
if (torrentURL.toString().isEmpty())
torrentURL = article[Article::KeyLink];
// If item does not have an ID, fall back to some other identifier.
QVariant &localId = article[Article::KeyId];
if (localId.toString().isEmpty())
localId = article.value(Article::KeyTorrentURL);
if (localId.toString().isEmpty())
localId = article.value(Article::KeyTitle);
if (localId.toString().isEmpty()) {
// The article could not be uniquely identified
// since it has no appropriate data.
// Just ignore it.
return;
}
if (m_articleIDs.contains(localId.toString())) {
// The article could not be uniquely identified
// since the Feed has duplicate identifiers.
// Just ignore it.
return;
}
m_articleIDs.insert(localId.toString());
m_result.articles.prepend(article);
}

View file

@ -31,6 +31,7 @@
#include <QList>
#include <QObject>
#include <QSet>
#include <QString>
#include <QVariantHash>
@ -65,9 +66,11 @@ namespace RSS
void parseRSSChannel(QXmlStreamReader &xml);
void parseAtomArticle(QXmlStreamReader &xml);
void parseAtomChannel(QXmlStreamReader &xml);
void addArticle(QVariantHash article);
QString m_baseUrl;
ParsingResult m_result;
QSet<QString> m_articleIDs;
};
}
}

View file

@ -419,24 +419,10 @@ int Feed::updateArticles(const QList<QVariantHash> &loadedArticles)
QVector<QVariantHash> newArticles;
newArticles.reserve(loadedArticles.size());
for (QVariantHash article : loadedArticles) {
QVariant &torrentURL = article[Article::KeyTorrentURL];
if (torrentURL.toString().isEmpty())
torrentURL = article[Article::KeyLink];
// If item does not have an ID, fall back to some other identifier.
QVariant &localId = article[Article::KeyId];
if (localId.toString().isEmpty())
localId = article.value(Article::KeyTorrentURL);
if (localId.toString().isEmpty())
localId = article.value(Article::KeyTitle);
if (localId.toString().isEmpty())
continue;
// If article has no publication date we use feed update time as a fallback.
// To prevent processing of "out-of-limit" articles we must not assign dates
// that are earlier than the dates of existing articles.
const Article *existingArticle = articleByGUID(localId.toString());
const Article *existingArticle = articleByGUID(article[Article::KeyId].toString());
if (existingArticle) {
dummyPubDate = existingArticle->date().addMSecs(-1);
continue;