|
|
@ -39,6 +39,8 @@ |
|
|
|
#include <QVariant> |
|
|
|
#include <QVariant> |
|
|
|
#include <QXmlStreamReader> |
|
|
|
#include <QXmlStreamReader> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "../rss_article.h" |
|
|
|
|
|
|
|
|
|
|
|
namespace |
|
|
|
namespace |
|
|
|
{ |
|
|
|
{ |
|
|
|
const char shortDay[][4] = { |
|
|
|
const char shortDay[][4] = { |
|
|
@ -280,36 +282,41 @@ void Parser::parseRssArticle(QXmlStreamReader &xml) |
|
|
|
|
|
|
|
|
|
|
|
while (!xml.atEnd()) { |
|
|
|
while (!xml.atEnd()) { |
|
|
|
xml.readNext(); |
|
|
|
xml.readNext(); |
|
|
|
|
|
|
|
const QString name(xml.name().toString()); |
|
|
|
|
|
|
|
|
|
|
|
if(xml.isEndElement() && xml.name() == "item") |
|
|
|
if (xml.isEndElement() && (name == QLatin1String("item"))) |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
if (xml.isStartElement()) { |
|
|
|
if (xml.isStartElement()) { |
|
|
|
if (xml.name() == "title") { |
|
|
|
const QString text(xml.readElementText().trimmed()); |
|
|
|
article["title"] = xml.readElementText().trimmed(); |
|
|
|
|
|
|
|
|
|
|
|
if (name == QLatin1String("title")) { |
|
|
|
|
|
|
|
article[Article::KeyTitle] = text; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "enclosure") { |
|
|
|
else if (name == QLatin1String("enclosure")) { |
|
|
|
if (xml.attributes().value("type") == "application/x-bittorrent") |
|
|
|
if (xml.attributes().value("type") == QLatin1String("application/x-bittorrent")) |
|
|
|
article["torrent_url"] = xml.attributes().value("url").toString(); |
|
|
|
article[Article::KeyTorrentURL] = xml.attributes().value(QLatin1String("url")).toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "link") { |
|
|
|
else if (name == QLatin1String("link")) { |
|
|
|
QString link = xml.readElementText().trimmed(); |
|
|
|
if (text.startsWith(QLatin1String("magnet:"), Qt::CaseInsensitive)) |
|
|
|
if (link.startsWith("magnet:", Qt::CaseInsensitive)) |
|
|
|
article[Article::KeyTorrentURL] = text; // magnet link instead of a news URL
|
|
|
|
article["torrent_url"] = link; // magnet link instead of a news URL
|
|
|
|
|
|
|
|
else |
|
|
|
else |
|
|
|
article["news_link"] = link; |
|
|
|
article[Article::KeyLink] = text; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "description") { |
|
|
|
else if (name == QLatin1String("description")) { |
|
|
|
article["description"] = xml.readElementText().trimmed(); |
|
|
|
article[Article::KeyDescription] = text; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "pubDate") { |
|
|
|
else if (name == QLatin1String("pubDate")) { |
|
|
|
article["date"] = parseDate(xml.readElementText().trimmed()); |
|
|
|
article[Article::KeyDate] = parseDate(text); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "author") { |
|
|
|
else if (name == QLatin1String("author")) { |
|
|
|
article["author"] = xml.readElementText().trimmed(); |
|
|
|
article[Article::KeyAuthor] = text; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "guid") { |
|
|
|
else if (name == QLatin1String("guid")) { |
|
|
|
article["id"] = xml.readElementText().trimmed(); |
|
|
|
article[Article::KeyId] = text; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
article[name] = text; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -353,33 +360,36 @@ void Parser::parseAtomArticle(QXmlStreamReader &xml) |
|
|
|
|
|
|
|
|
|
|
|
while (!xml.atEnd()) { |
|
|
|
while (!xml.atEnd()) { |
|
|
|
xml.readNext(); |
|
|
|
xml.readNext(); |
|
|
|
|
|
|
|
const QString name(xml.name().toString()); |
|
|
|
|
|
|
|
|
|
|
|
if (xml.isEndElement() && (xml.name() == "entry")) |
|
|
|
if (xml.isEndElement() && (name == QLatin1String("entry"))) |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
if (xml.isStartElement()) { |
|
|
|
if (xml.isStartElement()) { |
|
|
|
if (xml.name() == "title") { |
|
|
|
const QString text(xml.readElementText().trimmed()); |
|
|
|
article["title"] = xml.readElementText().trimmed(); |
|
|
|
|
|
|
|
|
|
|
|
if (name == QLatin1String("title")) { |
|
|
|
|
|
|
|
article[Article::KeyTitle] = text; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "link") { |
|
|
|
else if (name == QLatin1String("link")) { |
|
|
|
QString link = (xml.attributes().isEmpty() |
|
|
|
QString link = (xml.attributes().isEmpty() |
|
|
|
? xml.readElementText().trimmed() |
|
|
|
? text |
|
|
|
: xml.attributes().value("href").toString()); |
|
|
|
: xml.attributes().value(QLatin1String("href")).toString()); |
|
|
|
|
|
|
|
|
|
|
|
if (link.startsWith("magnet:", Qt::CaseInsensitive)) |
|
|
|
if (link.startsWith(QLatin1String("magnet:"), Qt::CaseInsensitive)) |
|
|
|
article["torrent_url"] = link; // magnet link instead of a news URL
|
|
|
|
article[Article::KeyTorrentURL] = link; // magnet link instead of a news URL
|
|
|
|
else |
|
|
|
else |
|
|
|
// Atom feeds can have relative links, work around this and
|
|
|
|
// Atom feeds can have relative links, work around this and
|
|
|
|
// take the stress of figuring article full URI from UI
|
|
|
|
// take the stress of figuring article full URI from UI
|
|
|
|
// Assemble full URI
|
|
|
|
// Assemble full URI
|
|
|
|
article["news_link"] = (m_baseUrl.isEmpty() ? link : m_baseUrl + link); |
|
|
|
article[Article::KeyLink] = (m_baseUrl.isEmpty() ? link : m_baseUrl + link); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else if ((xml.name() == "summary") || (xml.name() == "content")){ |
|
|
|
else if ((name == QLatin1String("summary")) || (name == QLatin1String("content"))){ |
|
|
|
if (doubleContent) { // Duplicate content -> ignore
|
|
|
|
if (doubleContent) { // Duplicate content -> ignore
|
|
|
|
xml.readNext(); |
|
|
|
xml.readNext(); |
|
|
|
|
|
|
|
|
|
|
|
while ((xml.name() != "summary") && (xml.name() != "content")) |
|
|
|
while ((xml.name() != QLatin1String("summary")) && (xml.name() != QLatin1String("content"))) |
|
|
|
xml.readNext(); |
|
|
|
xml.readNext(); |
|
|
|
|
|
|
|
|
|
|
|
continue; |
|
|
|
continue; |
|
|
@ -389,25 +399,28 @@ void Parser::parseAtomArticle(QXmlStreamReader &xml) |
|
|
|
// Actually works great for non-broken content too
|
|
|
|
// Actually works great for non-broken content too
|
|
|
|
QString feedText = xml.readElementText(QXmlStreamReader::IncludeChildElements); |
|
|
|
QString feedText = xml.readElementText(QXmlStreamReader::IncludeChildElements); |
|
|
|
if (!feedText.isEmpty()) |
|
|
|
if (!feedText.isEmpty()) |
|
|
|
article["description"] = feedText.trimmed(); |
|
|
|
article[Article::KeyDescription] = feedText.trimmed(); |
|
|
|
|
|
|
|
|
|
|
|
doubleContent = true; |
|
|
|
doubleContent = true; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "updated") { |
|
|
|
else if (name == QLatin1String("updated")) { |
|
|
|
// ATOM uses standard compliant date, don't do fancy stuff
|
|
|
|
// ATOM uses standard compliant date, don't do fancy stuff
|
|
|
|
QDateTime articleDate = QDateTime::fromString(xml.readElementText().trimmed(), Qt::ISODate); |
|
|
|
QDateTime articleDate = QDateTime::fromString(text, Qt::ISODate); |
|
|
|
article["date"] = (articleDate.isValid() ? articleDate : QDateTime::currentDateTime()); |
|
|
|
article[Article::KeyDate] = (articleDate.isValid() ? articleDate : QDateTime::currentDateTime()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "author") { |
|
|
|
else if (name == QLatin1String("author")) { |
|
|
|
xml.readNext(); |
|
|
|
xml.readNext(); |
|
|
|
while (xml.name() != "author") { |
|
|
|
while (xml.name() != QLatin1String("author")) { |
|
|
|
if (xml.name() == "name") |
|
|
|
if (xml.name() == QLatin1String("name")) |
|
|
|
article["author"] = xml.readElementText().trimmed(); |
|
|
|
article[Article::KeyAuthor] = xml.readElementText().trimmed(); |
|
|
|
xml.readNext(); |
|
|
|
xml.readNext(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "id") { |
|
|
|
else if (name == QLatin1String("id")) { |
|
|
|
article["id"] = xml.readElementText().trimmed(); |
|
|
|
article[Article::KeyId] = text; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
article[name] = text; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|