diff --git a/plugins/opds.koplugin/opdsbrowser.lua b/plugins/opds.koplugin/opdsbrowser.lua index b40fa1d98..257c31f7d 100644 --- a/plugins/opds.koplugin/opdsbrowser.lua +++ b/plugins/opds.koplugin/opdsbrowser.lua @@ -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 diff --git a/plugins/opds.koplugin/opdsparser.lua b/plugins/opds.koplugin/opdsparser.lua index 732190cc2..6fd1da93e 100644 --- a/plugins/opds.koplugin/opdsparser.lua +++ b/plugins/opds.koplugin/opdsparser.lua @@ -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 diff --git a/spec/unit/opds_spec.lua b/spec/unit/opds_spec.lua index a057a880a..6d71ac460 100644 --- a/spec/unit/opds_spec.lua +++ b/spec/unit/opds_spec.lua @@ -354,6 +354,30 @@ local pdf_acquisition_sample = [[ ]] +local multiple_authors_sample = [[ + + + urn:multiple:authors + Multiple authors + 2026-10-25T00:00:00Z + + The Wrong Box + urn:wrong:box + 2026-10-25T00:00:00Z + Robert Louis Stevenson + Lloyd Osbourne + + + + Treasure Island + urn:treasure:island + 2026-10-25T00:00:00Z + Robert Louis Stevenson + + + +]] + 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")