fetch some mrss metadata for atom feeds
This commit is contained in:
parent
f53b4d16c2
commit
14dda0623b
7
src/librssguard/services/standard/atomparser.cpp
Normal file → Executable file
7
src/librssguard/services/standard/atomparser.cpp
Normal file → Executable file
@ -47,6 +47,10 @@ Message AtomParser::extractMessage(const QDomElement& msg_element, QDateTime cur
|
|||||||
|
|
||||||
if (summary.isEmpty()) {
|
if (summary.isEmpty()) {
|
||||||
summary = textsFromPath(msg_element, m_atomNamespace, QSL("summary"), true).join(QSL(", "));
|
summary = textsFromPath(msg_element, m_atomNamespace, QSL("summary"), true).join(QSL(", "));
|
||||||
|
|
||||||
|
if (summary.isEmpty()) {
|
||||||
|
summary = mrssTextFromPath(msg_element, QSL("description"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we obtained maximum of information for title & description.
|
// Now we obtained maximum of information for title & description.
|
||||||
@ -95,6 +99,9 @@ Message AtomParser::extractMessage(const QDomElement& msg_element, QDateTime cur
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtain MRSS enclosures.
|
||||||
|
new_message.m_enclosures.append(mrssGetEnclosures(msg_element));
|
||||||
|
|
||||||
if (!last_link_alternate.isEmpty()) {
|
if (!last_link_alternate.isEmpty()) {
|
||||||
new_message.m_url = last_link_alternate;
|
new_message.m_url = last_link_alternate;
|
||||||
}
|
}
|
||||||
|
0
src/librssguard/services/standard/atomparser.h
Normal file → Executable file
0
src/librssguard/services/standard/atomparser.h
Normal file → Executable file
37
src/librssguard/services/standard/feedparser.cpp
Normal file → Executable file
37
src/librssguard/services/standard/feedparser.cpp
Normal file → Executable file
@ -8,7 +8,7 @@
|
|||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
FeedParser::FeedParser(QString data) : m_xmlData(std::move(data)) {
|
FeedParser::FeedParser(QString data) : m_xmlData(std::move(data)), m_mrssNamespace(QSL("http://search.yahoo.com/mrss/")) {
|
||||||
m_xml.setContent(m_xmlData, true);
|
m_xml.setContent(m_xmlData, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +45,41 @@ QList<Message> FeedParser::messages() {
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<Enclosure> FeedParser::mrssGetEnclosures(const QDomElement& msg_element) const {
|
||||||
|
QList<Enclosure> enclosures;
|
||||||
|
|
||||||
|
auto content_list = msg_element.elementsByTagNameNS(m_mrssNamespace, "content");
|
||||||
|
|
||||||
|
for (int i = 0; i < content_list.size(); i++) {
|
||||||
|
QDomElement elem_content = content_list.at(i).toElement();
|
||||||
|
QString url = elem_content.attribute(QSL("url"));
|
||||||
|
QString type = elem_content.attribute(QSL("type"));
|
||||||
|
|
||||||
|
if (!url.isEmpty() && !type.isEmpty()) {
|
||||||
|
enclosures.append(Enclosure(url, type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto thumbnail_list = msg_element.elementsByTagNameNS(m_mrssNamespace, "thumbnail");
|
||||||
|
|
||||||
|
for (int i = 0; i < thumbnail_list.size(); i++) {
|
||||||
|
QDomElement elem_content = thumbnail_list.at(i).toElement();
|
||||||
|
QString url = elem_content.attribute(QSL("url"));
|
||||||
|
|
||||||
|
if (!url.isEmpty()) {
|
||||||
|
enclosures.append(Enclosure(url, QSL("image/png")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return enclosures;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FeedParser::mrssTextFromPath(const QDomElement& msg_element, const QString& xml_path) const {
|
||||||
|
QString text = msg_element.elementsByTagNameNS(m_mrssNamespace, xml_path).at(0).toElement().text();
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList FeedParser::textsFromPath(const QDomElement& element, const QString& namespace_uri,
|
QStringList FeedParser::textsFromPath(const QDomElement& element, const QString& namespace_uri,
|
||||||
const QString& xml_path, bool only_first) const {
|
const QString& xml_path, bool only_first) const {
|
||||||
QStringList paths = xml_path.split('/');
|
QStringList paths = xml_path.split('/');
|
||||||
|
5
src/librssguard/services/standard/feedparser.h
Normal file → Executable file
5
src/librssguard/services/standard/feedparser.h
Normal file → Executable file
@ -10,12 +10,14 @@
|
|||||||
|
|
||||||
class FeedParser {
|
class FeedParser {
|
||||||
public:
|
public:
|
||||||
explicit FeedParser(QString data);
|
explicit FeedParser(QString data);
|
||||||
virtual ~FeedParser();
|
virtual ~FeedParser();
|
||||||
|
|
||||||
virtual QList<Message> messages();
|
virtual QList<Message> messages();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
QList<Enclosure> mrssGetEnclosures(const QDomElement& msg_element) const;
|
||||||
|
QString mrssTextFromPath(const QDomElement& msg_element, const QString& xml_path) const;
|
||||||
QStringList textsFromPath(const QDomElement& element, const QString& namespace_uri, const QString& xml_path, bool only_first) const;
|
QStringList textsFromPath(const QDomElement& element, const QString& namespace_uri, const QString& xml_path, bool only_first) const;
|
||||||
virtual QDomNodeList messageElements() = 0;
|
virtual QDomNodeList messageElements() = 0;
|
||||||
virtual QString feedAuthor() const;
|
virtual QString feedAuthor() const;
|
||||||
@ -24,6 +26,7 @@ class FeedParser {
|
|||||||
protected:
|
protected:
|
||||||
QString m_xmlData;
|
QString m_xmlData;
|
||||||
QDomDocument m_xml;
|
QDomDocument m_xml;
|
||||||
|
QString m_mrssNamespace;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FEEDPARSER_H
|
#endif // FEEDPARSER_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user