gotson / komga

Media server for comics/mangas/BDs/magazines/eBooks with API and OPDS support
https://komga.org
MIT License
3.76k stars 219 forks source link

ePub: Cover support for ePub files generated by older versions of Sigil #1497

Closed valdearg closed 3 months ago

valdearg commented 3 months ago

Describe your suggested feature

Bit of a strange request, but I've been looking at an issue with epub files and their cover not coming through. I think I've narrowed this down to how the Sigil software creates the epub file and the metadata in the content.opf file.

I have a book generated by the older version of Sigil which has the following metadata (summarised)

<?xml version="1.0" encoding="utf-8"?>
<package version="3.0" unique-identifier="pub-id" xmlns="http://www.idpf.org/2007/opf" xml:lang="en">
  <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
    <dc:title>The Troubles of Miss Nicola the Exorcist: Volume 1</dc:title>
    <dc:creator id="creator01">Ito Iino</dc:creator>
    <meta refines="#creator01" scheme="marc:relators" property="role">aut</meta>
    <meta refines="#creator01" property="display-seq">1</meta>
    <meta refines="#creator01" property="file-as">IINO, ITO</meta>
    <dc:creator id="creator02">Kinokohime</dc:creator>
    <meta refines="#creator02" scheme="marc:relators" property="role">ill</meta>
    <meta refines="#creator02" property="display-seq">2</meta>
    <meta refines="#creator02" property="file-as">KINOKOHIME</meta>
    <dc:creator id="creator03">Joshua Douglass-Molloy</dc:creator>
    <meta refines="#creator03" scheme="marc:relators" property="role">trl</meta>
    <meta refines="#creator03" property="display-seq">3</meta>
    <meta refines="#creator03" property="file-as">DOUGLASS-MOLLOY, JOSHUA</meta>
    <dc:creator id="creator04">Mario Mendez</dc:creator>
    <meta refines="#creator04" scheme="marc:relators" property="role">edt</meta>
    <meta refines="#creator04" property="display-seq">4</meta>
    <meta refines="#creator04" property="file-as">MENDEZ, MARIO</meta>
    <dc:publisher>J-Novel Club</dc:publisher>
    <dc:rights>Copyright © 2023 Ito Iino, Kinokohime</dc:rights>
    <dc:date>2023-08-04</dc:date>
    <dc:language>en</dc:language>
    <dc:identifier id="pub-id">9781718375376</dc:identifier>
    <meta refines="#pub-id" scheme="onix:codelist5" property="identifier-type">15</meta>
    <meta property="dcterms:modified">2023-10-31T03:10:02Z</meta>
    <meta name="Sigil version" content="0.9.14" />
  </metadata>

Then if I compare that to generated by a newer version of Sigil, this has an extra meta name for "cover":

  <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
    <dc:title>The Troubles of Miss Nicola the Exorcist: Volume 2</dc:title>
    <dc:creator id="creator01">Ito Iino</dc:creator>
    <meta property="role" refines="#creator01" scheme="marc:relators">aut</meta>
    <meta property="display-seq" refines="#creator01">1</meta>
    <meta property="file-as" refines="#creator01">IINO, ITO</meta>
    <dc:creator id="creator02">Kinokohime</dc:creator>
    <meta property="role" refines="#creator02" scheme="marc:relators">ill</meta>
    <meta property="display-seq" refines="#creator02">2</meta>
    <meta property="file-as" refines="#creator02">KINOKOHIME</meta>
    <dc:creator id="creator03">Joshua Douglass-Molloy</dc:creator>
    <meta property="role" refines="#creator03" scheme="marc:relators">trl</meta>
    <meta property="display-seq" refines="#creator03">3</meta>
    <meta property="file-as" refines="#creator03">DOUGLASS-MOLLOY, JOSHUA</meta>
    <dc:creator id="creator04">Mario Mendez</dc:creator>
    <meta property="role" refines="#creator04" scheme="marc:relators">edt</meta>
    <meta property="display-seq" refines="#creator04">4</meta>
    <meta property="file-as" refines="#creator04">MENDEZ, MARIO</meta>
    <dc:publisher>J-Novel Club</dc:publisher>
    <dc:rights>Copyright © 2023 Ito Iino, Kinokohime</dc:rights>
    <dc:date>2023-11-02</dc:date>
    <dc:language>en</dc:language>
    <dc:identifier id="pub-id">9781718375390</dc:identifier>
    <meta property="identifier-type" refines="#pub-id" scheme="onix:codelist5">15</meta>
    <meta property="dcterms:modified">2024-04-08T07:30:34Z</meta>
    <meta content="2.1.0" name="Sigil version"/>
    <meta name="cover" content="Cover.jpg"/>
  </metadata>

This works absolutely fine, Komga loads it perfectly fine.

If I manually edit the older Sigil made file and simply add in the <meta name="cover" content="Cover.jpg"/> line and analyse the file once more, this gets read perfectly.

I was therefore thinking either:

  1. Maybe test for a file in the ePub file named "cover.jpg", I'm not sure if this is universal however.
  2. In the section there's a line <item id="cover" href="Text/cover.xhtml" media-type="application/xhtml+xml"/>, it's probably way more complicated but the cover could be picked up from there by reading the <img alt="Cover" class="cover" src="../Images/Cover.jpg"/> section.
  3. Have a file named book name.cover.extension in the same directory as the epub, that could then be imported at the same time? E.g. "BookName.epub" and "BookName.cover.jpg"

Other details

No response

Acknowledgements

gotson commented 3 months ago

The first snippet does not have anything about cover, so Komga doesn't load anything. Epub is very strict about metadata, so if it's not standard epub, it won't be loaded.

<meta name="cover" content="Cover.jpg"/> this is epub2.

Epub3 has a manifest property called cover-image.


  1. Maybe test for a file in the ePub file named "cover.jpg", I'm not sure if this is universal however.

this is not standard, cover could be named anything

  1. In the section there's a line <item id="cover" href="Text/cover.xhtml" media-type="application/xhtml+xml"/>, it's probably way more complicated but the cover could be picked up from there by reading the <img alt="Cover" class="cover" src="../Images/Cover.jpg"/> section.

this is just the list of resources in the book, the fact that it's named "cover" is coincidental.

  1. Have a file named book name.cover.extension in the same directory as the epub, that could then be imported at the same time? E.g. "BookName.epub" and "BookName.cover.jpg"

Komga already supports local artwork: https://komga.org/docs/guides/local-artwork-assets/