From 6efae12ba0cea46637218029213ffdce6190c8a1 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Wed, 9 Apr 2025 14:01:04 +0300 Subject: [PATCH] OPDSBrowser: analyze acquisition mimetype (#13535) To handle non-standard relations. Closes #13520. --- plugins/opds.koplugin/opdsbrowser.lua | 32 ++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/plugins/opds.koplugin/opdsbrowser.lua b/plugins/opds.koplugin/opdsbrowser.lua index 985c8c1ed..f09a8bd36 100644 --- a/plugins/opds.koplugin/opdsbrowser.lua +++ b/plugins/opds.koplugin/opdsbrowser.lua @@ -37,11 +37,17 @@ local OPDSBrowser = Menu:extend{ search_template_type = "application/atom%+xml", acquisition_rel = "^http://opds%-spec%.org/acquisition", borrow_rel = "http://opds-spec.org/acquisition/borrow", - image_rel = "http://opds-spec.org/image", - image_rel_alt = "http://opds-spec.org/cover", -- ManyBooks.net, not in spec - thumbnail_rel = "http://opds-spec.org/image/thumbnail", - thumbnail_rel_alt = "http://opds-spec.org/thumbnail", -- ManyBooks.net, not in spec stream_rel = "http://vaemendis.net/opds-pse/stream", + image_rel = { + ["http://opds-spec.org/image"] = true, + ["http://opds-spec.org/cover"] = true, -- ManyBooks.net, not in spec + ["x-stanza-cover-image"] = true, + }, + thumbnail_rel = { + ["http://opds-spec.org/image/thumbnail"] = true, + ["http://opds-spec.org/thumbnail"] = true, -- ManyBooks.net, not in spec + ["x-stanza-cover-image-thumbnail"] = true, + }, root_catalog_title = nil, root_catalog_username = nil, @@ -386,11 +392,11 @@ function OPDSBrowser:genItemTableFromCatalog(catalog, item_url) end item_table.hrefs = hrefs - for _, entry in ipairs(feed.entry or {}) do + for __, entry in ipairs(feed.entry or {}) do local item = {} item.acquisitions = {} if entry.link then - for __, link in ipairs(entry.link) do + for ___, link in ipairs(entry.link) do local link_href = build_href(link.href) if link.type and link.type:find(self.catalog_type) and (not link.rel @@ -435,10 +441,16 @@ function OPDSBrowser:genItemTableFromCatalog(catalog, item_url) last_read = last_read and last_read > 0 and last_read or nil }) end - elseif link.rel == self.thumbnail_rel or link.rel == self.thumbnail_rel_alt then + elseif self.thumbnail_rel[link.rel] then item.thumbnail = link_href - elseif link.rel == self.image_rel or link.rel == self.image_rel_alt then + elseif self.image_rel[link.rel] then item.image = link_href + elseif link.rel ~= "alternate" and DocumentRegistry:hasProvider(nil, link.type) then + table.insert(item.acquisitions, { + type = link.type, + href = link_href, + title = link.title, + }) end -- This statement grabs the catalog items that are -- indicated by title="pdf" or whose type is @@ -459,7 +471,7 @@ function OPDSBrowser:genItemTableFromCatalog(catalog, item_url) end end end - local title = "Unknown" + local title = _("Unknown") if type(entry.title) == "string" then title = entry.title elseif type(entry.title) == "table" then @@ -468,7 +480,7 @@ function OPDSBrowser:genItemTableFromCatalog(catalog, item_url) end end item.text = title - local author = "Unknown Author" + local author = _("Unknown Author") if type(entry.author) == "table" and entry.author.name then author = entry.author.name if type(author) == "table" then