readium / r2-shared-js

Shared models for Readium Desktop
BSD 3-Clause "New" or "Revised" License
11 stars 11 forks source link

How can I tell the version using the publicationParser (e.g. EPUB 2 vs. EPUB 3)? #53

Open jdempcy opened 1 year ago

jdempcy commented 1 year ago

I see that you can get the version from the OPF, but that requires passing in a zip. We are currently using r2-shared-js and already have the publicationParser working (it works great! So thanks for that!). But we would like to be able to tell if it's an EPUB 2 or EPUB 3 or higher, just from the publicationParser.

Here is an excerpt of what we are doing:

        const pub = await publicationParser.PublicationParsePromise(path);

        if (typeof pub.Metadata.Title === "string") {
            bookTitle = pub.Metadata.Title;
            coverUrl = pub.GetCover()?.Href || '';
            manifest = serializable.TaJsonSerialize(pub);

            const zipInternal = pub.findFromInternal("zip");
            if (!zipInternal) {
                throw new Error("There is no publication zip!");
            }

It would be nice if we could check, for instance. pub.Version and be able to tell the EPUB version. Is there another way to do this?

Thanks! Jonah

danielweck commented 1 year ago

Hi Jonah, this might be useful to you, but the information would need to be hoisted up into the publication object:

https://github.com/readium/r2-shared-js/blob/8a61896183f5dfecfe011fac73775f898a262385/src/parser/epub-daisy-common.ts#L68-L83