Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 06-02-2012, 12:20 PM   #1
AlPe
Digital Amanuensis
AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.
 
AlPe's Avatar
 
Posts: 727
Karma: 1446357
Join Date: Dec 2011
Location: Turin, Italy
Device: Several eReaders and tablets
exlibris - add a nice ex libris to your EPUB eBook!

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.

Last edited by AlPe; 09-02-2014 at 02:53 PM.
AlPe is offline   Reply With Quote
Old 06-03-2012, 06:06 AM   #2
Indiana Joe
Flying eReader Monster
Indiana Joe began at the beginning.
 
Indiana Joe's Avatar
 
Posts: 12
Karma: 10
Join Date: Dec 2011
Location: Patavium
Device: Sony PRS650 - Kobo Mini - RIP Foxit eSlick
Good work AlPe.


Anyway if you want to set up the correct link, now you can.
Indiana Joe is offline   Reply With Quote
Advert
Old 06-03-2012, 07:28 AM   #3
AlPe
Digital Amanuensis
AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.
 
AlPe's Avatar
 
Posts: 727
Karma: 1446357
Join Date: Dec 2011
Location: Turin, Italy
Device: Several eReaders and tablets
Thanks Indiana, but since the eBook Club Italia forum is mainly in Italian, I decided to drop here the direct link to my wuala space.

However, for the interested reader: I posted the "main" discussion thread about exlibris on the EBCI forum at the following URL: http://forum.ebci.it/index.php?topic=67.0
AlPe is offline   Reply With Quote
Old 06-03-2012, 07:32 AM   #4
Terisa de morgan
Grand Sorcerer
Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.
 
Terisa de morgan's Avatar
 
Posts: 6,233
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
I'll give a try (and I'll pass to my friends), thank you very much. And 'll talk about your ebook club to a friend of mine who is very fluent in Italian (I'm only a basic student).

BTW, it's very very nice for me because I missed my ex-libris.
Terisa de morgan is offline   Reply With Quote
Old 06-03-2012, 07:47 AM   #5
AlPe
Digital Amanuensis
AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.
 
AlPe's Avatar
 
Posts: 727
Karma: 1446357
Join Date: Dec 2011
Location: Turin, Italy
Device: Several eReaders and tablets
Excellent, thanks!
AlPe is offline   Reply With Quote
Advert
Old 06-03-2012, 12:06 PM   #6
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
PeterT's Avatar
 
Posts: 12,166
Karma: 73448616
Join Date: Nov 2007
Location: Toronto
Device: Nexus 7, Clara, Touch, Tolino EPOS
@AlPe: Have you considered making this into a calibre plugin?
PeterT is offline   Reply With Quote
Old 06-03-2012, 03:07 PM   #7
AlPe
Digital Amanuensis
AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.
 
AlPe's Avatar
 
Posts: 727
Karma: 1446357
Join Date: Dec 2011
Location: Turin, Italy
Device: Several eReaders and tablets
I must confess that I do not like Calibre that much... but I can think about this idea, thank you for suggesting it.
AlPe is offline   Reply With Quote
Old 06-04-2012, 01:32 PM   #8
AlPe
Digital Amanuensis
AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.
 
AlPe's Avatar
 
Posts: 727
Karma: 1446357
Join Date: Dec 2011
Location: Turin, Italy
Device: Several eReaders and tablets
Ok here's my plan: I will decouple the library that actually adds the ex libris from the command line parsing stuff, and I will code three front-ends: CLI, GUI and a calibre plugin.

In the next release:

1) Parametric fields in the ex libris: you will write "EXLIBRIS_TITLE" in your XHTML source and exlibris will substitute it with the EPUB title read from its metadata (and the same for other fields).

2) Better support for external files referenced from the ex libris XHTML page.

3) A security check before unzipping the EPUB (hey, I assume you know what you are doing, but better safe than sorry...).

4) Insertion point in the TOC.

5) Time permitting: Calibre plugin and GUI.
AlPe is offline   Reply With Quote
Old 06-04-2012, 04:32 PM   #9
Freeshadow
temp. out of service
Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.
 
Posts: 2,792
Karma: 24285242
Join Date: May 2010
Location: Duisburg (DE)
Device: PB 623
If I'm not misunderstanding how it works, it might also be usable as an autograph insertion tool for authors. If I'm right, you might be interested in crosspost this to the writer's corner subforum.
Freeshadow is offline   Reply With Quote
Old 06-05-2012, 03:22 AM   #10
AlPe
Digital Amanuensis
AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.
 
AlPe's Avatar
 
Posts: 727
Karma: 1446357
Join Date: Dec 2011
Location: Turin, Italy
Device: Several eReaders and tablets
That's correct. I will post there as soon as I have coded a GUI.

I am considering passing strings as command line parameters, so that the ex libris template can be "personalized" on the fly, allowing the personalization of each copy.

Note that this tool can be used to watermark EPUBs as well, if one does not care about inserting hidden markers in the files and is fine with just a page summing up the book owner's data.
AlPe is offline   Reply With Quote
Old 06-05-2012, 09:54 AM   #11
Freeshadow
temp. out of service
Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.Freeshadow ought to be getting tired of karma fortunes by now.
 
Posts: 2,792
Karma: 24285242
Join Date: May 2010
Location: Duisburg (DE)
Device: PB 623
In fact the 1st use case I saw was an author handwriting a dedication on a small graphic tablet, saving said file as svg and using your tool to stick it to the book.
Freeshadow is offline   Reply With Quote
Old 06-07-2012, 04:17 PM   #12
AlPe
Digital Amanuensis
AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.
 
AlPe's Avatar
 
Posts: 727
Karma: 1446357
Join Date: Dec 2011
Location: Turin, Italy
Device: Several eReaders and tablets
A brief update: I decoupled the code inserting the ex libris into the EPUB from the command line argument parsing, creating a single "function library". Then, I moved the CLI stuff to a single CLI front-end.

I will include the ability of defining templates in the ex libris file, to be replaced by your own string(s) or the book metadata.

If anyone has already tried exlibris out and discovered any problems, I would like to try to correct them before the next release. You might want to post a message here or write me a PM, many thanks!

Last edited by AlPe; 06-07-2012 at 04:20 PM.
AlPe is offline   Reply With Quote
Old 06-08-2012, 02:38 PM   #13
AlPe
Digital Amanuensis
AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.
 
AlPe's Avatar
 
Posts: 727
Karma: 1446357
Join Date: Dec 2011
Location: Turin, Italy
Device: Several eReaders and tablets
I have just updated the initial post, with a link to v. 1.04, which includes:

1) solved a bug with backslashes under Windows;
2) better handling of command line options;
3) decoupled the library from the CLI frontend.

In the next release I plan to include templates (supporting reading the original EPUB metadata) and possibly a GUI. I am studying how to write a Calibre plugin, so that it will be added as well, but not before a couple of weeks.
AlPe is offline   Reply With Quote
Old 06-13-2012, 08:29 AM   #14
AlPe
Digital Amanuensis
AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.
 
AlPe's Avatar
 
Posts: 727
Karma: 1446357
Join Date: Dec 2011
Location: Turin, Italy
Device: Several eReaders and tablets
I have just updated the initial post, with a link to v. 1.05, which includes:

1) added a sanity check before uncompressing the original EPUB file;
2) added the support for string replacement in the ex libris page, from metadata or user-specified strings provided as -r argument on the command line;
3) added --supported-mimetype-identifiers and --supported-metadata-identifiers help options;
4) other minor improvements.

The GUI (and Calibre plugin) must wait until the next release, since I am quite busy job hunting...

If you find out bugs, please let me know, thank you!
AlPe is offline   Reply With Quote
Old 06-14-2012, 01:31 PM   #15
AlPe
Digital Amanuensis
AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.
 
AlPe's Avatar
 
Posts: 727
Karma: 1446357
Join Date: Dec 2011
Location: Turin, Italy
Device: Several eReaders and tablets
I have just updated the initial post, with a link to v. 1.06, which includes:

1) solved a CDATA bug in metadata;
2) added --spine and --toc options;
3) better examples in the zip file.

The GUI (and Calibre plugin) must wait until the next release, since I am quite busy job hunting...

If you find out bugs, please let me know, thank you!
AlPe is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New ebook reader software "libris Me" - looking for beta testers irgendwienet News 38 12-02-2010 03:32 PM
exLibris - free epub/fb2 reader lyubimovm Apple Devices 6 12-01-2010 01:15 AM
Neue ebook Software libris Me (beta Tester gesucht) irgendwienet Software 21 11-04-2010 11:55 AM
Android ESV Study Bible (EPUB ebook) - working nice on EE leo315 enTourage Archive 1 08-04-2010 10:13 AM


All times are GMT -4. The time now is 07:41 AM.


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