This commit is contained in:
jpirnay
2026-05-10 21:06:55 +02:00
parent 80eb889256
commit 5304086bcd
5 changed files with 37 additions and 21 deletions
+6 -2
View File
@@ -4,6 +4,7 @@
#include <Logging.h>
#include <cstring>
#include <utility>
namespace {
// Returns the length of href after trimming trailing slashes.
@@ -198,7 +199,7 @@ void XMLCALL OpdsParser::startElement(void* userData, const XML_Char* name, cons
self->currentEntry.acquisitionLinks.push_back(acquisition);
}
} else if (rel && type && strstr(rel, "opds-spec.org/image") != nullptr &&
strstr(rel, "thumbnail") == nullptr && strstr(type, "image/jpeg") != nullptr &&
strstr(rel, "thumbnail") == nullptr && strncmp(type, "image/", 6) == 0 &&
self->currentEntry.imageHref.empty()) {
self->currentEntry.imageHref = href;
} else if (type && strstr(type, "application/atom+xml") != nullptr) {
@@ -238,7 +239,10 @@ void XMLCALL OpdsParser::endElement(void* userData, const XML_Char* name) {
if (strcmp(name, "entry") == 0 || strstr(name, ":entry") != nullptr) {
if (!self->currentEntry.title.empty() && !self->currentEntry.href.empty()) {
if (self->onEntryParsed) self->onEntryParsed(self->currentEntry);
if (self->onEntryParsed) {
self->onEntryParsed(std::move(self->currentEntry));
self->currentEntry = OpdsEntry{};
}
}
self->inEntry = false;
} else if (self->inEntry) {
+10 -7
View File
@@ -43,14 +43,17 @@ using OpdsBook = OpdsEntry;
*
* Usage:
* OpdsParser parser;
* if (parser.parse(xmlData, xmlLength)) {
* for (const auto& entry : parser.getEntries()) {
* if (entry.type == OpdsEntryType::BOOK) {
* // Downloadable book
* } else {
* // Navigation link to another catalog
* }
* parser.onEntryParsed = [](OpdsEntry entry) {
* if (entry.type == OpdsEntryType::BOOK) {
* // Process downloadable book
* } else {
* // Process navigation link
* }
* };
*
* // Entries are emitted immediately as they are parsed from the stream.
* if (parser.parse(xmlData, xmlLength)) {
* // Parsing completed successfully
* }
*/
class OpdsParser final : public Print {