Code Monkey home page Code Monkey logo

Comments (5)

Difegue avatar Difegue commented on June 3, 2024

Thank you for the report - Would you happen to be able to share a small epub file that exhibits the problem so I can try it out?

I suspect we should look at the content.opf file when building the image list for epubs instead of just sorting by image name like we do with everything else.

from lanraragi.

yihuasteven avatar yihuasteven commented on June 3, 2024

from lanraragi.

Difegue avatar Difegue commented on June 3, 2024

@yihuasteven Sorry for the delay -- unfortunately you will need to upload the epub directly in this issue, attaching them via email does not work. Thanks!

from lanraragi.

yihuasteven avatar yihuasteven commented on June 3, 2024

@yihuasteven Sorry for the delay -- unfortunately you will need to upload the epub directly in this issue, attaching them via email does not work. Thanks!

No problem, here is the equb file. Thanks.
SP-ABC.zip

from lanraragi.

Difegue avatar Difegue commented on June 3, 2024

Had some time so I took a deeper look in the epub spec:

Annoyingly so, we can't just look at content.opf, since that name is not fixed in the spec and can be anything (it's vol.opf in the epub linked above, for example).

Instead, we have to first look at META-INF/container.xml to know the location of the OPF file:

<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
    <rootfiles> 
       <rootfile full-path="vol.opf" media-type="application/oebps-package+xml" />
    </rootfiles>
</container>

Then we can open and parse the OPF file to get the image order:

<?xml version="1.0" encoding="UTF-8" ?>
<package version="2.0" unique-identifier="MOXBID" xmlns="http://www.idpf.org/2007/opf">
  <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
    [...]
  </metadata>
  <manifest>
    <item id="ncx" href="xml/vol.ncx" media-type="application/x-dtbncx+xml"/>

    <item id="Page_1" href="html/1.html" media-type="application/xhtml+xml"/> 
    <item id="Page_2" href="html/2.html" media-type="application/xhtml+xml"/> 
    <item id="Page_3" href="html/3.html" media-type="application/xhtml+xml"/> 
    <item id="Page_4" href="html/4.html" media-type="application/xhtml+xml"/> 
    <item id="Page_5" href="html/5.html" media-type="application/xhtml+xml"/> 
    <item id="Page_6" href="html/6.html" media-type="application/xhtml+xml"/> 
    <item id="Page_7" href="html/7.html" media-type="application/xhtml+xml"/> 
    <item id="Page_8" href="html/8.html" media-type="application/xhtml+xml"/> 
    <item id="Page_9" href="html/9.html" media-type="application/xhtml+xml"/> 
    <item id="Page_10" href="html/10.html" media-type="application/xhtml+xml"/> 
    <item id="Page_11" href="html/11.html" media-type="application/xhtml+xml"/> 
    <item id="Page_12" href="html/12.html" media-type="application/xhtml+xml"/> 
    <item id="Page_createby"  href="html/createby.html" media-type="application/xhtml+xml"/> 
    <item id="Page_cover"     href="html/cover.jpg.html" media-type="application/xhtml+xml"/>

    <item id="cover_img" href="image/cover.jpg" media-type="image/jpeg" properties="cover-image" />

    <item id="img_1" href="image/vol-000458.jpg" media-type="image/jpeg"/> 
    <item id="img_2" href="image/vol-008535.jpg" media-type="image/jpeg"/> 
    <item id="img_3" href="image/vol-004233.jpg" media-type="image/jpeg"/> 
    <item id="img_4" href="image/vol-007116.jpg" media-type="image/jpeg"/> 
    <item id="img_5" href="image/vol-008993.jpg" media-type="image/jpeg"/> 
    <item id="img_6" href="image/vol-007881.jpg" media-type="image/jpeg"/> 
    <item id="img_7" href="image/vol-000962.jpg" media-type="image/jpeg"/> 
    <item id="img_8" href="image/vol-008719.jpg" media-type="image/jpeg"/> 
    <item id="img_9" href="image/vol-008906.jpg" media-type="image/jpeg"/> 
    <item id="img_10" href="image/vol-004248.jpg" media-type="image/jpeg"/> 
    <item id="img_11" href="image/vol-003600.jpg" media-type="image/jpeg"/> 
    <item id="img_12" href="image/vol-005270.jpg" media-type="image/jpeg"/> 
    <item id="img_createby" href="image/createby.png" media-type="image/png"/>
    <item id="css" href="css/style.css" media-type="text/css"/>
    <item id="font01" href="misc/Courier.ttf" media-type="application/x-font-ttf"/>
  </manifest>
  <spine toc="ncx">
    <itemref idref="Page_cover" />

    <itemref idref="Page_1" /> 
    <itemref idref="Page_2" /> 
    <itemref idref="Page_3" /> 
    <itemref idref="Page_4" /> 
    <itemref idref="Page_5" /> 
    <itemref idref="Page_6" /> 
    <itemref idref="Page_7" /> 
    <itemref idref="Page_8" /> 
    <itemref idref="Page_9" /> 
    <itemref idref="Page_10" /> 
    <itemref idref="Page_11" /> 
    <itemref idref="Page_12" /> 
    <itemref idref="Page_createby" /> 
  </spine>
  <guide>
      <reference type="cover" href="image/cover.jpg" title="封面" />
  </guide>
</package>

Turns out that the OPF file itself doesn't contain the order of the images either, just the list of the images -- The actual order needs to be figured out by parsing the html files..

In this epub, the first image in the OPF file is image/vol-000458.jpg, but opening 1.html shows it's actually image/vol-007881.jpg. (what kind of madman does this i stg)

So basically, in order to have perfect image order support for epub, you need to implement the epub spec in full.

I'm going to put this in volunteers welcome, but I think it'd be quite an ordeal...
An EPUB Parser perl library could help here. (Alternatively, we could just use an epub reader javascript library in the front-end but that'd require a bunch of custom code as well)

In the meantime @yihuasteven, what I can recommend would be to use an OPDS Client alongside your LRR server (with page streaming turned off) - Most OPDS clients are designed for EPUBs and will download and parse the full file themselves.

from lanraragi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.