Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default cover is not generated in ePub #113

Closed
odedia opened this issue Jul 20, 2019 · 2 comments · May be fixed by #114
Closed

Default cover is not generated in ePub #113

odedia opened this issue Jul 20, 2019 · 2 comments · May be fixed by #114

Comments

@odedia
Copy link

odedia commented Jul 20, 2019

The ePub is generated well, but the default cover is not present in the book. On Apple Books, this means that i don't see the image of the cover, only a text with the name of the book.

If I convert from ePub to ePub in calibre, I do get the cover, however this messes up other indentation parts of the book.

I think the default is just a cover.jpeg at the root of the folder (not really sure, I just checked the output of the calibre generated ePub)

@xyl1null
Copy link

xyl1null commented Jul 22, 2019

A bit tweak should suffice.

Before digging in, I'd like to underline some general knowledges about EPUB specification.
The content.opf file, which describes the structure of the .epub in XML, is not correctly configured for Books app and the right format should be:

 <?xml version="1.0" encoding="UTF-8"?>
  <package xmlns="http://www.idpf.org/2007/opf"
         xmlns:redirect="http://xml.apache.org/xalan/redirect"
         version="1.0"
         unique-identifier="bookid">
   <metadata xmlns:opf="http://www.idpf.org/2007/opf"
             xmlns:dc="http://purl.org/dc/elements/1.1/">
      <dc:identifier id="bookid">XXXXXXXXXXXXX</dc:identifier>
      ...
      <meta name="cover" content="cover-image"/>
      ...
   </metadata>
   <manifest>
      ...
      <item id="cover-image"
            href="images/xxx.jpg"
            media-type="image/jpeg"
            properties="cover-image"/>
      ...
   </manifest>
   <spine toc="ncx">
    <itemref idref="xx" />
    ...
   </spine>
   <guide>
      <reference type="cover" title="Cover" href="cover.xhtml"/>
   </guide>
  </package>

For some reason in the third version they deprecate the .opf format and substitute with .ocf. More info on wikipedia.

Anyway, I extend <meta name="cover" content="/path/to/cover"/> into two separate sections, one in meta,

"<meta name=\"cover\" content=\"cover-image\"/>\n" \

and append the other in manifest ,

manifest.append("<item id=\"cover-image\" href=\"{0}\" media-type=\"image/png\" properties=\"cover-image\" />".format("/path/to/cover"))

You were right about cover.* but not always the case, thus I present another method to extract path/to/real/cover from api not the thumbnail as in get_default_cover()

def create_cover(self):
        response = self.requests_provider(self.api_url)
        parsed = response.json()
        for i in parsed['chapters']:
            # very vulnerable as publishers may differ
            if 'cover.' or 'Cover.' or 'titlepage.' in i:
                cover_url = i
                break

        if cover_url:
            cover_response = self.requests_provider(cover_url)
            cover_parsed = cover_response.json()
            imgAttrib = cover_parsed['images']
            if imgAttrib:
                lst2str = "".join(list(map(str, imgAttrib)))
                return "Images/" + lst2str.split('/')[-1]
            else:
                # if no covers found, fall back to fuzzy thumbnails
                return "Images/" + self.get_default_cover()
         else:
            return "Images/" + self.get_default_cover()

Hope that help solve your problem and please feel free to contribute.
Cheers!

@lorenzodifuccia
Copy link
Owner

Use Calibre's ebook-convert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants