OPDS: keep every author of an Atom entry (#16303)

The parser kept only the last of several <author> elements, so the catalog list and the download filename showed only the last author. Collect them like entry, link and Url, and join their names as the OPDS 2.0 path does.
This commit is contained in:
chemicalsno authored and GitHub committed 2026-10-26 08:07:17 +01:00
1 parent 28099b3915
commit dad1ad4433
3 files changed
+63 -10

No files matched your search

+20 -9
View File
@@ -985,18 +985,29 @@ function OPDSBrowser:genItemTableFromCatalog(catalog, item_url)
end
item.text = title
local author = _("Unknown Author")
if type(entry.author) == "table" and entry.author.name then
author = entry.author.name
if type(author) == "table" then
if #author > 0 then
author = table.concat(author, ", ")
else
-- we may get an empty table on https://gallica.bnf.fr/opds
author = nil
if type(entry.author) == "table" then
local names = {}
local empty_name = false
for _, entry_author in ipairs(entry.author) do
local name = type(entry_author) == "table" and entry_author.name or nil
if type(name) == "table" then
if #name > 0 then
name = table.concat(name, ", ")
else
-- we may get an empty table on https://gallica.bnf.fr/opds
empty_name = true
name = nil
end
end
if type(name) == "string" then
table.insert(names, name)
end
end
if author then
if #names > 0 then
author = table.concat(names, ", ")
item.text = title .. " - " .. author
elseif empty_name then
author = nil
end
end
item.title = title
+1 -1
View File
@@ -54,7 +54,7 @@ function OPDSParser:createFlatXTable(xlex, curr_element)
-- if it does, if it's a table, add to it
-- if it doesn't, then add a table
local tab = self:createFlatXTable(xlex)
if txt == "entry" or txt == "link" or txt == "Url" then
if txt == "entry" or txt == "link" or txt == "Url" or txt == "author" then
if curr_element[txt] == nil then
curr_element[txt] = {}
end
+42
View File
@@ -354,6 +354,30 @@ local pdf_acquisition_sample = [[
</feed>
]]
local multiple_authors_sample = [[
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>urn:multiple:authors</id>
<title>Multiple authors</title>
<updated>2026-10-25T00:00:00Z</updated>
<entry>
<title>The Wrong Box</title>
<id>urn:wrong:box</id>
<updated>2026-10-25T00:00:00Z</updated>
<author><name>Robert Louis Stevenson</name></author>
<author><name>Lloyd Osbourne</name></author>
<link href="/opds/download/97/epub/" type="application/epub+zip" rel="http://opds-spec.org/acquisition" />
</entry>
<entry>
<title>Treasure Island</title>
<id>urn:treasure:island</id>
<updated>2026-10-25T00:00:00Z</updated>
<author><name>Robert Louis Stevenson</name></author>
<link href="/opds/download/68/epub/" type="application/epub+zip" rel="http://opds-spec.org/acquisition" />
</entry>
</feed>
]]
describe("OPDS module", function()
local socketutil
local CookieJar, OPDSClient, OPDSParser, OPDSBrowser
@@ -467,6 +491,15 @@ describe("OPDS module", function()
assert.are.same(entry.category.label, "Приключения")
assert.are.same(entry.link[1].title, "Все книги серии «Капитан Немо»")
end)
it("should keep every author of an entry", function()
local catalog = OPDSParser:parse(multiple_authors_sample)
local entries = catalog.feed.entry
assert.are.same(#entries[1].author, 2)
assert.are.same(entries[1].author[1].name, "Robert Louis Stevenson")
assert.are.same(entries[1].author[2].name, "Lloyd Osbourne")
assert.are.same(#entries[2].author, 1)
assert.are.same(entries[2].author[1].name, "Robert Louis Stevenson")
end)
end)
describe("OPDS browser module", function()
@@ -539,6 +572,15 @@ describe("OPDS module", function()
assert.are.same("Entry Two", item_table[2].title)
assert.are.same("https://www.cbeta.org/opds/index.php?vol=X", item_table[2].url)
end)
it("should list every author of an entry", function()
local catalog = OPDSParser:parse(multiple_authors_sample)
local item_table = OPDSBrowser:genItemTableFromCatalog(catalog, "https://example.com/opds/")
assert.are.same("Robert Louis Stevenson, Lloyd Osbourne", item_table[1].author)
assert.are.same("The Wrong Box - Robert Louis Stevenson, Lloyd Osbourne", item_table[1].text)
assert.are.same("Robert Louis Stevenson", item_table[2].author)
assert.are.same("Robert Louis Stevenson, Lloyd Osbourne - The Wrong Box", (OPDSBrowser:getFileName(item_table[1])))
end)
it("should use the main URL for faceted links as long as faceted links aren't properly supported #internet", function()
local catalog = OPDSParser:parse(facet_sample)
local item_table = OPDSBrowser:genItemTableFromCatalog(catalog, "http://flibusta.is/opds")