Browse Source

Merge pull request #8966 from glassez/rss-date

Use RSS feed update time as a fallback. Closes #8959
adaptive-webui-19844
Vladimir Golovnev 7 years ago committed by GitHub
parent
commit
935bb5bd1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      src/base/rss/rss_article.cpp
  2. 2
      src/base/rss/rss_autodownloadrule.cpp
  3. 8
      src/base/rss/rss_feed.cpp

21
src/base/rss/rss_article.cpp

@ -38,6 +38,19 @@ @@ -38,6 +38,19 @@
using namespace RSS;
namespace
{
QVariantHash articleDataFromJSON(const QJsonObject &jsonObj)
{
auto varHash = jsonObj.toVariantHash();
// JSON object store DateTime as string so we need to convert it
varHash[Article::KeyDate] =
QDateTime::fromString(jsonObj.value(Article::KeyDate).toString(), Qt::RFC2822Date);
return varHash;
}
}
const QString Article::KeyId(QStringLiteral("id"));
const QString Article::KeyDate(QStringLiteral("date"));
const QString Article::KeyTitle(QStringLiteral("title"));
@ -60,6 +73,9 @@ Article::Article(Feed *feed, const QVariantHash &varHash) @@ -60,6 +73,9 @@ Article::Article(Feed *feed, const QVariantHash &varHash)
, m_isRead(varHash.value(KeyIsRead, false).toBool())
, m_data(varHash)
{
if (!m_date.isValid())
throw std::runtime_error("Bad RSS Article data");
// If item does not have a guid, fall back to some other identifier
if (m_guid.isEmpty())
m_guid = varHash.value(KeyTorrentURL).toString();
@ -77,11 +93,8 @@ Article::Article(Feed *feed, const QVariantHash &varHash) @@ -77,11 +93,8 @@ Article::Article(Feed *feed, const QVariantHash &varHash)
}
Article::Article(Feed *feed, const QJsonObject &jsonObj)
: Article(feed, jsonObj.toVariantHash())
: Article(feed, articleDataFromJSON(jsonObj))
{
// JSON object store DateTime as string so we need to convert it
m_date = QDateTime::fromString(jsonObj.value(KeyDate).toString(), Qt::RFC2822Date);
m_data[KeyDate] = m_date;
}
QString Article::guid() const

2
src/base/rss/rss_autodownloadrule.cpp

@ -384,6 +384,8 @@ bool AutoDownloadRule::accepts(const QVariantHash &articleData) @@ -384,6 +384,8 @@ bool AutoDownloadRule::accepts(const QVariantHash &articleData)
m_dataPtr->previouslyMatchedEpisodes.append(m_dataPtr->lastComputedEpisode);
m_dataPtr->lastComputedEpisode.clear();
}
return true;
}
AutoDownloadRule &AutoDownloadRule::operator=(const AutoDownloadRule &other)

8
src/base/rss/rss_feed.cpp

@ -212,7 +212,13 @@ void Feed::handleParsingFinished(const RSS::Private::ParsingResult &result) @@ -212,7 +212,13 @@ void Feed::handleParsingFinished(const RSS::Private::ParsingResult &result)
m_lastBuildDate = result.lastBuildDate;
int newArticlesCount = 0;
for (const QVariantHash &varHash : result.articles) {
const QDateTime now {QDateTime::currentDateTime()};
for (QVariantHash varHash : result.articles) {
// if article has no publication date we use feed update time as a fallback
QVariant &articleDate = varHash[Article::KeyDate];
if (!articleDate.toDateTime().isValid())
articleDate = now;
try {
auto article = new Article(this, varHash);
if (addArticle(article))

Loading…
Cancel
Save