fix: Prefer epub format over derived formats when downloading from opds server (#1480)
## Summary * **What is the goal of this PR?** Prefer epub format over kepub or other formats offered from an OPDS server * **What changes are included?** ## Additional Context Should address #1419 --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**< NO >**_ --------- Co-authored-by: Arthur Tazhitdinov <lisnake@gmail.com>
This commit is contained in:
co-authored by
Arthur Tazhitdinov
parent
3800179595
commit
a7aa4c55d8
@@ -110,8 +110,16 @@ void XMLCALL OpdsParser::startElement(void* userData, const XML_Char* name, cons
|
|||||||
if (self->inEntry) {
|
if (self->inEntry) {
|
||||||
if (rel && type && strstr(rel, "opds-spec.org/acquisition") != nullptr &&
|
if (rel && type && strstr(rel, "opds-spec.org/acquisition") != nullptr &&
|
||||||
strcmp(type, "application/epub+zip") == 0) {
|
strcmp(type, "application/epub+zip") == 0) {
|
||||||
self->currentEntry.type = OpdsEntryType::BOOK;
|
// Prefer plain EPUB links over derived formats when multiple
|
||||||
self->currentEntry.href = href;
|
// acquisition links are present for one entry.
|
||||||
|
const bool isPlainEpub = strstr(href, ".epub") != nullptr || strstr(href, "/epub/") != nullptr;
|
||||||
|
const bool alreadyHasPlainEpub = self->currentEntry.type == OpdsEntryType::BOOK &&
|
||||||
|
(self->currentEntry.href.find(".epub") != std::string::npos ||
|
||||||
|
self->currentEntry.href.find("/epub/") != std::string::npos);
|
||||||
|
if (self->currentEntry.type != OpdsEntryType::BOOK || (isPlainEpub && !alreadyHasPlainEpub)) {
|
||||||
|
self->currentEntry.type = OpdsEntryType::BOOK;
|
||||||
|
self->currentEntry.href = href;
|
||||||
|
}
|
||||||
} else if (type && strstr(type, "application/atom+xml") != nullptr) {
|
} else if (type && strstr(type, "application/atom+xml") != nullptr) {
|
||||||
if (self->currentEntry.type != OpdsEntryType::BOOK) {
|
if (self->currentEntry.type != OpdsEntryType::BOOK) {
|
||||||
self->currentEntry.type = OpdsEntryType::NAVIGATION;
|
self->currentEntry.type = OpdsEntryType::NAVIGATION;
|
||||||
|
|||||||
Reference in New Issue
Block a user