OPDSBrowser: analyze acquisition mimetype (#13535)

To handle non-standard relations.
Closes #13520.
This commit is contained in:
hius07
2025-04-09 14:01:04 +03:00
committed by GitHub
parent 142566f1b0
commit 6efae12ba0

View File

@@ -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