![]() |
#1 |
Junior Member
![]() Posts: 9
Karma: 10
Join Date: Nov 2015
Device: none
|
Custom metadata command line for a fixed layout comic
Hi Calibre community !
I'm new to to world of ebooks, and I try to publish my first comic as an ebook... I'm also a Linux user, so I created a really simple bash script to convert a serie of jpg files to a CBZ file and then an ePUB : zip $joinedfilename.cbz *.jpg ebook-convert $joinedfilename.cbz $joinedfilename.epub --authors "$creator" --publisher "$creator" --title "$title" --isbn "$ebookIsbn" --pubdate "$pubDate" --no-default-epub-cover --dont-grayscale --keep-aspect-ratio And It work like a charm, thanks to Calibre ! but I discovered today than Amazon want more metadatas : "Error Description :Your book content appears to be fixed-format layout, but it is missing a fixed-format metadata tag. Please consult sections 4.1 and 5.1 of the Kindle Publishing Guidelines to determine the best formatting choice for your content." So, it's required I add ![]() <meta property="rendition:layout">pre-paginated</meta> and <meta name="original-resolution" content="584x754"/> to my epub ... But with ebook-convert and ebook-meta, I can't find a way to add them... I can edit the ebook withe the graphical client, but I'd like to automate the process... Any Idea ? Thanks a lot in advance ! |
![]() |
![]() |
![]() |
#2 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 don't think you can, not with ebook-convert or ebook-meta.
ebook-meta is for setting user-facing metadata, like title, series, author, publisher, etc. You cannot set formatting metadata with it. As for ebook-convert, it relies on calibre's Input/Output plugins, which do not understand Fixed-Format. The fact that they sort-of-resemble Fixed-Format books is incidental. It should be easy to unzip the epub though and insert the right meta tags with awk or sed. You can also use a vimscript, since if your EDITOR=vim then Code:
calibre-debug --explode-book $joinedfilename.epub Now, even if you do that, I'd still want to check the book to make sure it works as expected. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Junior Member
![]() Posts: 9
Karma: 10
Join Date: Nov 2015
Device: none
|
Thanks for your quick answer eschwartz !
To be more precise, I founded that converting to CBZ first will force ebook-convert to set up a fixed format ePub... so I sort of cheated the fixed layout ![]() So ... with your suggestion... maybe a script which unzip the epub, edit the content.opf file with the correct metadata, and zip it again would work ? EDIT : with an additional epub check ? |
![]() |
![]() |
![]() |
#4 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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)
|
Yeah, should work.
Rezipping an EPUB is tricky, of course, because you have to deal with the mimetype file -- "can't be compressed, multiple passes to zip" garbage. ![]() That's why I like calibre-debug --explode-book or alternatively the Editor, but they are geared toward human oversight not scripting. I'm not really sure how you'd find the exploded ebook directory via a script in order to modify it. Usually it pops up the File Browser. ![]() ![]() That's why I suggested a vimscript, you could probably load it automatically via a filetype plugin, apply the changes, save and exit without touching a single key... ... or maybe I enjoy making things harder, because it's more fun. ![]() |
![]() |
![]() |
![]() |
#5 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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)
|
And yes, I caught the fact that you converted to CBZ to trick it into "sort-of-resemble Fixed-Format books" in an incidental way.
![]() Nice trick, but of course calibre doesn't know to add explicit Fixed-Format references. |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Junior Member
![]() Posts: 9
Karma: 10
Join Date: Nov 2015
Device: none
|
![]()
I just tested it out...
Googling around, I ended up with this little script (called edit.sh): ---------- #!/bin/sh mkdir edit mv "$1" edit cd edit unzip "$1" CONTENT='\t\t<meta property="rendition:layout">pre-paginated</meta>\n\t\t<meta name="original-resolution" content="584x754"/>' sed -i '/<\/metadata>/i\'"$CONTENT" content.opf zip -r "$1" . mv "$1" .. cd .. rm -r edit ---------- and surprisingly, it seem to work ![]() ![]() Thanks a lot for showing me the way eschwartz ! |
![]() |
![]() |
![]() |
#7 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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)
|
Not exactly.
I think you need to pass the `-D` switch as well. Otherwise you can see you have a listing for the actual directories as well, which I *think* might be a problem, and if you take a look at the raw file, the mimetype is moved over. I have no idea how exactly the mimetype is read, but apparently it's very fragile! ![]() Must be right at the beginning, blah blah blah... Code:
#!/bin/bash epub="$(realpath "$1")" tmp_epub=$(mktemp -d) unzip "$epub" -d $tmp_epub pushd $tmp_epub CONTENT='\t\t<meta property="rendition:layout">pre-paginated</meta>\n\t\t<meta name="original-resolution" content="584x754"/>' sed -i '/<\/metadata>/i\'"$CONTENT" content.opf zip -X0 "$epub" mimetype zip -rDX9 "$epub" * -x mimetype pushd rm -rf $tmp_epub ![]() And it's "cleaner" to put the extracted files in /tmp - right? ![]() You can also redirect most of the output to /dev/null if you want to make it really professional and distribute it. Last edited by eschwartz; 11-09-2015 at 01:24 PM. |
![]() |
![]() |
![]() |
#8 |
Junior Member
![]() Posts: 9
Karma: 10
Join Date: Nov 2015
Device: none
|
Thanks again eschwartz
![]() Yes, your version seem much more solid and clean ! I'm a drawer, not a coder, so I admit my scripts are far from perfect... If I publish my whole script on github, which is meant to generate .cbz, .epub, .pdf for ebooks and print from individual .svg files, are you interested in reviewing it ? I'm sure you will give it a valuable clean up and boost ![]() |
![]() |
![]() |
![]() |
#9 |
Junior Member
![]() Posts: 9
Karma: 10
Join Date: Nov 2015
Device: none
|
Actually, it make me decide to publish my work.... So here it is : https://github.com/nylnook/climate-frogs-comic
and the export script in particular if you are curious : https://github.com/nylnook/climate-f...xport-comic.sh Cheers ! |
![]() |
![]() |
![]() |
#10 |
Junior Member
![]() Posts: 9
Karma: 10
Join Date: Nov 2015
Device: none
|
After some more tests, the best way to avoid mimetypes errors is to not touch the mimetype at all...
So here is the updated script : Code:
epub="$(realpath "$joinedfilename.epub")" tmp_epub=$(mktemp -d) unzip "$epub" -d $tmp_epub pushd $tmp_epub CONTENT='\t\t<meta name="fixed-layout" content="true"/>\n\t\t<meta name="original-resolution" content="584x754"/>' sed -i '/<\/metadata>/i\'"$CONTENT" content.opf zip -r "$epub" * -x mimetype pushd rm -rf $tmp_epub |
![]() |
![]() |
![]() |
Tags |
linux |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Add custom page via command line | cinek | Conversion | 2 | 04-01-2014 11:33 AM |
bulk metadata download through command line | woodapple | Calibre | 13 | 09-02-2013 04:50 PM |
How do I indent each line of my fixed-layout epub? | krausj | ePub | 7 | 06-12-2013 11:17 AM |
Adding custom fields when importing books via command line | chemi | Library Management | 7 | 02-25-2013 10:16 PM |
Command Line Search and Replace Metadata | metalhammer | Calibre | 1 | 05-02-2012 05:13 AM |