Improve image and content parsing from feed

This commit is contained in:
Bart De Vries 2023-02-21 10:20:45 +01:00
parent 0c46952d4a
commit 585378b86c

View File

@ -98,13 +98,14 @@ void UpdateFeedJob::processFeed(Syndication::FeedPtr feed)
QDateTime current = QDateTime::currentDateTime(); QDateTime current = QDateTime::currentDateTime();
query.bindValue(QStringLiteral(":lastUpdated"), current.toSecsSinceEpoch()); query.bindValue(QStringLiteral(":lastUpdated"), current.toSecsSinceEpoch());
QString image = feed->image()->url(); QString image;
// If there is no regular image tag, then try the itunes tags // First try the itunes tags, if not, fall back to regular image tag
if (image.isEmpty()) { if (otherItems.value(QStringLiteral("http://www.itunes.com/dtds/podcast-1.0.dtdimage")).hasAttribute(QStringLiteral("href"))) {
if (otherItems.value(QStringLiteral("http://www.itunes.com/dtds/podcast-1.0.dtdimage")).hasAttribute(QStringLiteral("href"))) { image = otherItems.value(QStringLiteral("http://www.itunes.com/dtds/podcast-1.0.dtdimage")).attribute(QStringLiteral("href"));
image = otherItems.value(QStringLiteral("http://www.itunes.com/dtds/podcast-1.0.dtdimage")).attribute(QStringLiteral("href")); } else {
} image = feed->image()->url();
} }
if (image.startsWith(QStringLiteral("/"))) if (image.startsWith(QStringLiteral("/")))
image = QUrl(m_url).adjusted(QUrl::RemovePath).toString() + image; image = QUrl(m_url).adjusted(QUrl::RemovePath).toString() + image;
query.bindValue(QStringLiteral(":image"), image); query.bindValue(QStringLiteral(":image"), image);
@ -282,10 +283,12 @@ bool UpdateFeedJob::processEntry(Syndication::ItemPtr entry)
entryDetails.read = m_isNewFeed ? m_markUnreadOnNewFeed : false; // if new feed, then check settings entryDetails.read = m_isNewFeed ? m_markUnreadOnNewFeed : false; // if new feed, then check settings
entryDetails.isNew = !m_isNewFeed; // if new feed, then mark none as new entryDetails.isNew = !m_isNewFeed; // if new feed, then mark none as new
if (!entry->description().isEmpty()) // Take the longest text, either content or description
entryDetails.content = entry->description(); if (entry->content().length() > entry->description().length()) {
else
entryDetails.content = entry->content(); entryDetails.content = entry->content();
} else {
entryDetails.content = entry->description();
}
// Look for image in itunes tags // Look for image in itunes tags
if (otherItems.value(QStringLiteral("http://www.itunes.com/dtds/podcast-1.0.dtdimage")).hasAttribute(QStringLiteral("href"))) { if (otherItems.value(QStringLiteral("http://www.itunes.com/dtds/podcast-1.0.dtdimage")).hasAttribute(QStringLiteral("href"))) {