Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 07-17-2014, 09:11 AM   #1
bquinn
Junior Member
bquinn began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Jul 2014
Device: any ereader
Angry Creating valid epub from command line using zip

Is there really a way to use zip on the command line to create an epub file that validates properly with epubcheck? I have tried every sequence of command line commands that I can find on the Internet and they all say they work, but I get exactly the same errors no matter how I do it. I suspect that the people who claim that zip creates valid epub files have not validated them with epubcheck. The files this method creates seem to work on a few ereaders, but not all of them, and it always fails epubcheck.

Here is one of the typical ways that I've tried to do it, but it always gives me the same errors.

Code:
$ rm ./test-epub-3-0-1.epub 
$ zip -X0 ./test-epub-3-0-1.epub mimetype
  adding: mimetype (stored 0%)
$ zip -rDX9 ./test-epub-3-0-1.epub META-INF -x mimetype
  adding: META-INF/container.xml (deflated 30%)
$ zip -rDX9 ./test-epub-3-0-1.epub OEBPS -x mimetype
  adding: OEBPS/cover.xhtml (deflated 29%)
  adding: OEBPS/title_pages.xhtml (deflated 30%)
  adding: OEBPS/chapter01.xhtml (deflated 30%)
  adding: OEBPS/epub.css (stored 0%)
  adding: OEBPS/toc.xhtml (deflated 32%)
  adding: OEBPS/chapter03.xhtml (deflated 30%)
  adding: OEBPS/notes.xhtml (deflated 30%)
  adding: OEBPS/MyBook.opf (deflated 67%)
  adding: OEBPS/chapter02.xhtml (deflated 33%)
$ cd ..
$ java -jar epubcheck-3.0.1/epubcheck-3.0.1.jar test-epub-3-0-1.epub 
Epubcheck Version 3.0.1

ERROR: test-epub-3-0-1.epub: Mimetype entry must not have an extra field in its ZIP header
Validating against EPUB version 3.0
ERROR: test-epub-3-0-1.epub/mimetype: Mimetype file should contain only the string "application/epub+zip".
ERROR: test-epub-3-0-1.epub/XHTML/MyBook.opf(2,161): element "package" missing required attribute "unique-identifier"
ERROR: test-epub-3-0-1.epub/XHTML/MyBook.opf(2,161): unique-identifier attribute in package element must be present and have a value
ERROR: test-epub-3-0-1.epub/XHTML/MyBook.opf(9,13): element "metadata" incomplete; missing required element "dc:identifier"
ERROR: test-epub-3-0-1.epub/XHTML/MyBook.opf(3,12): assertion failed: package dcterms:modified meta element must occur exactly once
ERROR: test-epub-3-0-1.epub/XHTML/MyBook.opf(10,12): assertion failed: Exactly one manifest item must declare the 'nav' property (number of 'nav' items: 0).
ERROR: test-epub-3-0-1.epub/XHTML/MyBook.opf: unique-identifier attribute in package element must reference an existing identifier element id
I am on Linux and don't have access to many of the utilities and I would much prefer to create my own epub files, but I am not sure there is a real way to create truly valid epub files using zip. I know that epubcheck works because it returns no errors for epub files that I have downloaded, but there does not appear to be a way to make one on the command line that validates. I know that my mimetype file is correct and at least the first two errors should not be there. I haven't looked into the other errors because it doesn't even get past the mimetype file.

Does anyone have any recommendations on how I might be able to do this so that epubcheck will validate the file?
bquinn is offline   Reply With Quote
Old 07-17-2014, 09:16 AM   #2
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,546
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
I use a script like this all the time:

Code:
#!/bin/bash

rm -f "$1"
zip -X0 "$1" mimetype
zip -X9Dr "$1" META-INF OEBPS
which is basically the same you do.

Now, the question is, what is the content of your "mimetype" file? It should be:

Code:
application/epub+zip
and only that, no newline at the end or anything else.
Jellby is offline   Reply With Quote
Advert
Old 07-17-2014, 10:03 AM   #3
Toxaris
Wizard
Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.
 
Toxaris's Avatar
 
Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
Your problem is not the zip commands, but the content...
Toxaris is offline   Reply With Quote
Old 07-17-2014, 10:43 AM   #4
bquinn
Junior Member
bquinn began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Jul 2014
Device: any ereader
The contents of my mimetype file are exactly what Jellby shows in the example, with no newline character, and I have not been able to eliminate that error. I haven't begun to look at the other errors. Will epubcheck show errors for the mimetype file if the real problem is in some other file?

Last edited by bquinn; 07-17-2014 at 10:46 AM.
bquinn is offline   Reply With Quote
Old 07-17-2014, 11:03 AM   #5
j.p.s
Grand Sorcerer
j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.
 
Posts: 5,772
Karma: 103362673
Join Date: Apr 2011
Device: pb360
Quote:
Originally Posted by bquinn View Post
The contents of my mimetype file are exactly what Jellby shows in the example, with no newline character, and I have not been able to eliminate that error. I haven't begun to look at the other errors. Will epubcheck show errors for the mimetype file if the real problem is in some other file?
What is the output from:

od -t x1 mimetype
j.p.s is offline   Reply With Quote
Advert
Old 07-18-2014, 12:45 AM   #6
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
I would suggest using ebook-convert (the command-line interface to calibre's conversion utility).

Also, epubcheck is reporting "ERROR: test-epub-3-0-1.epub/mimetype: Mimetype file should contain only the string "application/epub+zip"." which seems to indicate that there is something fishy there.
eschwartz is offline   Reply With Quote
Old 07-18-2014, 03:15 AM   #7
Toxaris
Wizard
Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.
 
Toxaris's Avatar
 
Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
Quote:
Originally Posted by bquinn View Post
The contents of my mimetype file are exactly what Jellby shows in the example, with no newline character, and I have not been able to eliminate that error. I haven't begun to look at the other errors. Will epubcheck show errors for the mimetype file if the real problem is in some other file?
Could you look at the mimetype file with a hex-editor? There could be a strange character there. The commands you use should work.
Other than that, your OPF is not correct. You are missing an identifier and it seems not to be complete. Did you create the OPF by hand?
Toxaris is offline   Reply With Quote
Old 07-18-2014, 12:49 PM   #8
j.p.s
Grand Sorcerer
j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.
 
Posts: 5,772
Karma: 103362673
Join Date: Apr 2011
Device: pb360
Quote:
Originally Posted by Toxaris View Post
Could you look at the mimetype file with a hex-editor? There could be a strange character there. The commands you use should work.
Other than that, your OPF is not correct. You are missing an identifier and it seems not to be complete. Did you create the OPF by hand?
Wouldn't posting the output of
od -t x1 mimetype
in a message here do the same thing and short circuit all ambiguities and miscommunications that happen when people attempt to discuss technical details in natural language?
j.p.s is offline   Reply With Quote
Old 07-18-2014, 04:13 PM   #9
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
The obvious solution is to use calibre, whose job is to package ebooks. The command-line interface to the conversion module accepts an OPF as input.

Or use the editor which handles all packaging and leaves you free to focus on the content.

Oh yeah, and I think Kovid finished the plugin system because it's an optional toolbar in the editor now. So extra functionality can be added in new an excitind ways.

Last edited by eschwartz; 07-18-2014 at 04:17 PM.
eschwartz is offline   Reply With Quote
Old 03-22-2015, 06:43 AM   #10
Steve_White
Junior Member
Steve_White began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Mar 2015
Location: Potsdam, Germany
Device: Kobo Aura
Create the ebook with the -X option, to stop it adding the "extra field" to the zip (the first error message), and '-Z store' to avoid compressing the mimetype file.

The mimetype file should have length 20 bytes. Check with command 'ls -l'.
If the length is greater, you probably have a newline at the end. But most editors put this on automatically. To make a mimetype file,

echo -n "application/epub+zip" > mimetype

Then create the book like this (change names where appropriate)

zip -Z store -Xr MyBook.epub mimetype
zip -r MyBook.epub META-INF/
zip -r MyBook.epub Content/

Cheers!
Steve_White is offline   Reply With Quote
Reply

Tags
epub zip epubcheck


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
"Remove the dependency on the zip command line tool when developing plugins"? JimmXinu Plugins 2 07-13-2012 02:09 PM
Ebook conversion (EPUB to MOBI) via command line ebooklab Conversion 4 09-16-2011 09:34 PM
Command line conversion of a URL to ePub bmwr1200c Recipes 3 08-11-2011 02:42 PM
How to specify command line option for epub format kiklop74 Calibre 15 05-14-2010 04:24 AM
Any command line to edit epub meta data? bthoven ePub 2 03-25-2010 04:15 AM


All times are GMT -4. The time now is 10:00 PM.


MobileRead.com is a privately owned, operated and funded community.