Browse Source

Fix RSS parsing

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
12280c6a0f
  1. 43
      src/rss/rssarticle.cpp
  2. 47
      src/rss/rssfeed.cpp

43
src/rss/rssarticle.cpp

@ -221,28 +221,29 @@ RssArticlePtr xmlToRssArticle(RssFeed* parent, QXmlStreamReader& xml) @@ -221,28 +221,29 @@ RssArticlePtr xmlToRssArticle(RssFeed* parent, QXmlStreamReader& xml)
QDateTime date;
QString author;
Q_ASSERT(xml.isStartElement() && xml.name() == "item");
while(!xml.atEnd()) {
xml.readNext();
while (xml.readNextStartElement()) {
if (xml.name() == "title")
title = xml.readElementText();
else if (xml.name() == "enclosure") {
if (xml.attributes().value("type") == "application/x-bittorrent")
torrentUrl = xml.attributes().value("url").toString();
}
else if (xml.name() == "link")
link = xml.readElementText();
else if (xml.name() == "description")
description = xml.readElementText();
else if (xml.name() == "pubDate")
date = RssArticle::parseDate(xml.readElementText());
else if (xml.name() == "author")
author = xml.readElementText();
else if (xml.name() == "guid")
guid = xml.readElementText();
else {
qDebug() << "Skipping item tag: " << xml.name();
xml.skipCurrentElement();
if(xml.isEndElement() && xml.name() == "item")
break;
if (xml.isStartElement()) {
if (xml.name() == "title")
title = xml.readElementText();
else if (xml.name() == "enclosure") {
if (xml.attributes().value("type") == "application/x-bittorrent")
torrentUrl = xml.attributes().value("url").toString();
}
else if (xml.name() == "link")
link = xml.readElementText();
else if (xml.name() == "description")
description = xml.readElementText();
else if (xml.name() == "pubDate")
date = RssArticle::parseDate(xml.readElementText());
else if (xml.name() == "author")
author = xml.readElementText();
else if (xml.name() == "guid")
guid = xml.readElementText();
}
}

47
src/rss/rssfeed.cpp

@ -214,31 +214,32 @@ void RssFeed::parseRSSChannel(QXmlStreamReader& xml) @@ -214,31 +214,32 @@ void RssFeed::parseRSSChannel(QXmlStreamReader& xml)
qDebug() << Q_FUNC_INFO;
Q_ASSERT(xml.isStartElement() && xml.name() == "channel");
while (xml.readNextStartElement()) {
if (xml.name() == "title") {
m_title = xml.readElementText();
if (m_alias == url())
rename(m_title);
}
else if (xml.name() == "image") {
QString icon_path = xml.attributes().value("url").toString();
if (!icon_path.isEmpty()) {
m_iconUrl = icon_path;
m_manager->rssDownloader()->downloadUrl(m_iconUrl);
while(!xml.atEnd()) {
xml.readNext();
if (xml.isStartElement()) {
if (xml.name() == "title") {
m_title = xml.readElementText();
if (m_alias == url())
rename(m_title);
}
}
else if (xml.name() == "item") {
RssArticlePtr article = xmlToRssArticle(this, xml);
qDebug() << "Found RSS Item, valid: " << (article ? "True" : "False");
if (article) {
QString guid = article->guid();
if (m_articles.contains(guid) && m_articles[guid]->isRead())
article->markAsRead();
m_articles[guid] = article;
else if (xml.name() == "image") {
QString icon_path = xml.attributes().value("url").toString();
if (!icon_path.isEmpty()) {
m_iconUrl = icon_path;
m_manager->rssDownloader()->downloadUrl(m_iconUrl);
}
}
else if (xml.name() == "item") {
RssArticlePtr article = xmlToRssArticle(this, xml);
qDebug() << "Found RSS Item, valid: " << (article ? "True" : "False");
if (article) {
QString guid = article->guid();
if (m_articles.contains(guid) && m_articles[guid]->isRead())
article->markAsRead();
m_articles[guid] = article;
}
}
} else {
qDebug() << "Skipping RSS tag: " << xml.name();
xml.skipCurrentElement();
}
}
}

Loading…
Cancel
Save