IMPORTANT: please note that the source code is now available on GitHub: https://github.com/pettarin/exlibris
Hi all,
I would like to share a Python script that I have developed to add an
ex libris to a (not DRM-ed) EPUB. The project was prompted by
eBookLuke.
You can download it (it is released under GNU GPL 3) from this link:
https://www.wuala.com/pettarin/EBCI/...y=eIUNfmKr7aB2
UPDATED to v. 1.0.14: added ex libris removal
UPDATED to v. 1.0.13: fixed a bug under Windows, forcing reading the input files in UTF8, alignment with the Calibre plugin
UPDATED to v. 1.0.10: fixed a bug in the path sanitization function, alignment with the Calibre plugin
UPDATED to v. 1.08: added a GUI, in English and in Italian.
UPDATED to v. 1.07: now the user can also select the insertion point of the ex libris in the TOC; added --no-guide, --guide-string and --toc-string switches
IMPORTANT: the option switch
-i, which was used to specify the insertion point of the ex libris in the spine, has been renamed to
-s (spine) to be consistent with
-t (TOC) switch.
UPDATED to v. 1.06: solved a CDATA bug in metadata, added --spine and --toc options, better examples in the zip file
UPDATED to v. 1.05: added support for string (metadata/user specified) string replacement in the ex libris page, and other minor improvements.
You will get a ZIP file with several Python .py files (exlibris.py, exlibris-cli.py, exlibris-gui.py and exlibris-gui-it.py) and four directories containing an ex libris example each.
I have developed it as a command line tool, but now there is also a GUI written in Tkinter, for the maximum portability and the least code footprint.
The Calibre plugin can be installed via the Calibre plugin manager (look for "Ex libris") or downloaded from this discussion:
https://www.mobileread.com/forums/sho...d.php?t=188619
I have tested it on several EPUBs (under Debian and Windows) and it should be quite robust; however if you find out bugs or strange behaviors, please let me know.
If you like this project, I ask you to consider supporting the
eBook Club Italia, a non-profit association that promotes reading -- especially digital reading --- in Italy. It also runs the wonderful
Museum of the eBook (you can browse it in English!).
You can help through a donation or by becoming a member.
For screenshots of the GUI version, please visit
this post.
I report here the usage message of the command line version:
Code:
NAME
exlibris-cli - CLI frontend to exlibris: add a nice ex libris to your EPUB eBook
SYNOPSIS
$ python exlibris-cli.py --help
$ python exlibris-cli.py --supported-mimetype-identifiers
$ python exlibris-cli.py --supported-metadata-identifiers
$ python exlibris-cli.py book.epub --spine
$ python exlibris-cli.py book.epub --toc
$ python exlibris-cli.py book.epub [new.epub] --remove
$ python exlibris-cli.py book.epub new.epub exlibris.xhtml [OPTIONS]
DESCRIPTION
Insert exlibris.xhtml inside book.epub and create new.epub.
If -h or --help option is given, display this usage message.
If -s option is not given, add the exlibris page as the last element of the spine.
If -t option is not given, add the exlibris page as the last element of the TOC.
If --spine (resp., --toc) option is given, print the elements of the spine (resp., TOC).
If --remove option is given, remove the ex libris from book.epub [and create new.epub].
OPTIONS
-d DIR: include all the recognized files contained in DIR.
Use this option if your ex libris XHTML page references CSS or image files.
-k: do not delete the temporary directory ('tmp').
-r DIC: replace the given strings in the ex libris page.
DIC must have the following format: "key1=value1; key2=value2; ... ; keyN=valueN".
exlibris will replace [%key1%] in the ex libris XHTML page with value1, and so on.
exlibris automagically replaces placeholders like [%title%], [%aut%], ... with the eBook metadata.
(Use --supported-metadata-identifiers to list all the supported metadata identifiers.)
-s NUM: insert the exlibris as the NUM-th element of the spine.
Use '1' or 'first' to insert the exlibris as the first element.
Use 'last' to insert the exlibris as the last element (default behavior).
Use 'ask' to get a list of possible insertion points and select it interactively.
-t NUM: insert the exlibris as the NUM-th element of the TOC.
Use '1' or 'first' to insert the exlibris as the first element.
Use 'last' to insert the exlibris as the last element (default behavior).
Use 'ask' to get a list of possible insertion points and select it interactively.
--guide-string STR: use STR as the guide string for the ex libris
--keep: do not delete the temporary directory ('tmp').
--no-guide: do not insert the ex libris in the guide section
--toc-string STR: use STR as the TOC string for the ex libris
EXAMPLES
$ python exlibris-cli.py book.epub new.epub exlibris.xhtml
$ python exlibris-cli.py book.epub new.epub exlibris.xhtml -s 1
$ python exlibris-cli.py book.epub new.epub exlibris.xhtml -s first
$ python exlibris-cli.py book.epub new.epub exlibris.xhtml -s 1984
$ python exlibris-cli.py book.epub new.epub exlibris.xhtml -s last
$ python exlibris-cli.py book.epub new.epub exlibris.xhtml -s first -t last
$ python exlibris-cli.py book.epub new.epub exlibris.xhtml -s ask -t ask
$ python exlibris-cli.py book.epub new.epub res/exlibris.xhtml -d res/
$ python exlibris-cli.py book.epub new.epub res/exlibris.xhtml -s first -t first -d res/
$ python exlibris-cli.py book.epub new.epub exlibris.xhtml -r "owner=Alberto; phrase=Happy Birthday! "
$ python exlibris-cli.py book.epub --spine
$ python exlibris-cli.py book.epub --toc
$ python exlibris-cli.py book.epub --remove
$ python exlibris-cli.py book.epub new.epub --remove
$ python exlibris-cli.py book.epub new.epub exlibris.xhtml -s ask -t ask --toc-string "Happy Birthday!"
$ python exlibris-cli.py book.epub new.epub exlibris.xhtml --guide-string "Ex Libris"
$ python exlibris-cli.py book.epub new.epub exlibris.xhtml -s first -t first --no-guide
LIMITATIONS
1) Your eBook input file must be "EPUB 2.0.1"-compliant,
and your ex libris input file must be "XHTML 1.1 strict"-compliant,
otherwise exlibris is not guaranteed to work properly and might produce an invalid EPUB file.
2) Currently exlibris includes the additional files specified by '-d' option
using their extension to get the proper media-type field.
Please name your file consistently.
For example, do not name a JPEG image 'image.svg' but use 'image.jpg' or 'image.jpeg'.
(Use --supported-mimetype-identifiers to list all the supported extensions.)
AUTHOR
Written by Alberto Pettarin, suggested by Luca "Luke" Calcinai.
REPORTING BUGS
Please write an email to alberto AT albertopettarin DOT it
or visit <http://www.albertopettarin.it/>
COPYRIGHT
Copyright (c) 2012 Alberto Pettarin.
License GNU GPL version 3 <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.