|
|
@ -280,36 +280,39 @@ 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 == "item")) |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
if (xml.isStartElement()) { |
|
|
|
if (xml.isStartElement()) { |
|
|
|
if (xml.name() == "title") { |
|
|
|
const QString text(xml.readElementText().trimmed()); |
|
|
|
article["title"] = xml.readElementText().trimmed(); |
|
|
|
article[name] = text; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (name == "title") { |
|
|
|
|
|
|
|
article["title"] = text; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "enclosure") { |
|
|
|
else if (name == "enclosure") { |
|
|
|
if (xml.attributes().value("type") == "application/x-bittorrent") |
|
|
|
if (xml.attributes().value("type") == "application/x-bittorrent") |
|
|
|
article["torrent_url"] = xml.attributes().value("url").toString(); |
|
|
|
article["torrent_url"] = xml.attributes().value("url").toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "link") { |
|
|
|
else if (name == "link") { |
|
|
|
QString link = xml.readElementText().trimmed(); |
|
|
|
if (text.startsWith("magnet:", Qt::CaseInsensitive)) |
|
|
|
if (link.startsWith("magnet:", Qt::CaseInsensitive)) |
|
|
|
article["torrent_url"] = 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["news_link"] = text; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "description") { |
|
|
|
else if (name == "description") { |
|
|
|
article["description"] = xml.readElementText().trimmed(); |
|
|
|
article["description"] = text; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "pubDate") { |
|
|
|
else if (name == "pubDate") { |
|
|
|
article["date"] = parseDate(xml.readElementText().trimmed()); |
|
|
|
article["date"] = parseDate(text); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "author") { |
|
|
|
else if (name == "author") { |
|
|
|
article["author"] = xml.readElementText().trimmed(); |
|
|
|
article["author"] = text; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "guid") { |
|
|
|
else if (name == "guid") { |
|
|
|
article["id"] = xml.readElementText().trimmed(); |
|
|
|
article["id"] = text; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -353,17 +356,21 @@ 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 == "entry")) |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
if (xml.isStartElement()) { |
|
|
|
if (xml.isStartElement()) { |
|
|
|
if (xml.name() == "title") { |
|
|
|
const QString text(xml.readElementText().trimmed()); |
|
|
|
article["title"] = xml.readElementText().trimmed(); |
|
|
|
article[name] = text; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (name == "title") { |
|
|
|
|
|
|
|
article["title"] = text; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "link") { |
|
|
|
else if (name == "link") { |
|
|
|
QString link = (xml.attributes().isEmpty() |
|
|
|
QString link = (xml.attributes().isEmpty() |
|
|
|
? xml.readElementText().trimmed() |
|
|
|
? text |
|
|
|
: xml.attributes().value("href").toString()); |
|
|
|
: xml.attributes().value("href").toString()); |
|
|
|
|
|
|
|
|
|
|
|
if (link.startsWith("magnet:", Qt::CaseInsensitive)) |
|
|
|
if (link.startsWith("magnet:", Qt::CaseInsensitive)) |
|
|
@ -375,7 +382,7 @@ void Parser::parseAtomArticle(QXmlStreamReader &xml) |
|
|
|
article["news_link"] = (m_baseUrl.isEmpty() ? link : m_baseUrl + link); |
|
|
|
article["news_link"] = (m_baseUrl.isEmpty() ? link : m_baseUrl + link); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else if ((xml.name() == "summary") || (xml.name() == "content")){ |
|
|
|
else if ((name == "summary") || (name == "content")){ |
|
|
|
if (doubleContent) { // Duplicate content -> ignore
|
|
|
|
if (doubleContent) { // Duplicate content -> ignore
|
|
|
|
xml.readNext(); |
|
|
|
xml.readNext(); |
|
|
|
|
|
|
|
|
|
|
@ -393,12 +400,12 @@ void Parser::parseAtomArticle(QXmlStreamReader &xml) |
|
|
|
|
|
|
|
|
|
|
|
doubleContent = true; |
|
|
|
doubleContent = true; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "updated") { |
|
|
|
else if (name == "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["date"] = (articleDate.isValid() ? articleDate : QDateTime::currentDateTime()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "author") { |
|
|
|
else if (name == "author") { |
|
|
|
xml.readNext(); |
|
|
|
xml.readNext(); |
|
|
|
while (xml.name() != "author") { |
|
|
|
while (xml.name() != "author") { |
|
|
|
if (xml.name() == "name") |
|
|
|
if (xml.name() == "name") |
|
|
@ -406,8 +413,8 @@ void Parser::parseAtomArticle(QXmlStreamReader &xml) |
|
|
|
xml.readNext(); |
|
|
|
xml.readNext(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (xml.name() == "id") { |
|
|
|
else if (name == "id") { |
|
|
|
article["id"] = xml.readElementText().trimmed(); |
|
|
|
article["id"] = text; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|