python-ebooklib-0.15~ds0.orig/ 0000700 0001750 0001750 00000000000 12326462732 016165 5 ustar alessio alessio python-ebooklib-0.15~ds0.orig/samples/ 0000700 0001750 0001750 00000000000 12326462732 017631 5 ustar alessio alessio python-ebooklib-0.15~ds0.orig/samples/04_markdown_parse/ 0000700 0001750 0001750 00000000000 12326462732 023150 5 ustar alessio alessio python-ebooklib-0.15~ds0.orig/samples/04_markdown_parse/README.md 0000644 0001750 0001750 00000000410 12326461175 024434 0 ustar alessio alessio # epub2markdown This is just a simple example and not utility script you should use for converting your ebooks. ## Usage epub2markdown my_ebook.epub ## Dependencies You need to install [Pandoc](http://johnmacfarlane.net/pandoc/) for this script to work. python-ebooklib-0.15~ds0.orig/samples/04_markdown_parse/epub2markdown.py 0000755 0001750 0001750 00000002406 12326461175 026321 0 ustar alessio alessio #!/usr/bin/env python import sys import subprocess import os import os.path from ebooklib import epub # This is just a basic example which can easily break in real world. if __name__ == '__main__': # read epub book = epub.read_epub(sys.argv[1]) # get base filename from the epub base_name = os.path.basename(os.path.splitext(sys.argv[1])[0]) for item in book.items: # convert into markdown if this is html if isinstance(item, epub.EpubHtml): proc = subprocess.Popen(['pandoc', '-f', 'html', '-t', 'markdown', '-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE ) content, error = proc.communicate(item.content) file_name = os.path.splitext(item.file_name)[0]+'.md' else: file_name = item.file_name content = item.content # create needed directories dir_name = '%s/%s' % (base_name, os.path.dirname(file_name)) if not os.path.exists(dir_name): os.makedirs(dir_name) print '>> ', file_name # write content to file f = open('%s/%s' % (base_name, file_name), 'w') f.write(content) f.close() python-ebooklib-0.15~ds0.orig/samples/03_advanced_create/ 0000700 0001750 0001750 00000000000 12326462732 023223 5 ustar alessio alessio python-ebooklib-0.15~ds0.orig/samples/03_advanced_create/README.md 0000644 0001750 0001750 00000000201 12326461175 024505 0 ustar alessio alessio Advanced create =============== Create simple EPUB3 using some of advanced features of EbookLib. ## Start python create.py python-ebooklib-0.15~ds0.orig/samples/03_advanced_create/create.py 0000644 0001750 0001750 00000004514 12326461175 025056 0 ustar alessio alessio # coding=utf-8 from ebooklib import epub if __name__ == '__main__': book = epub.EpubBook() # add metadata book.set_identifier('sample123456') book.set_title('Sample book') book.set_language('en') book.add_author('Aleksandar Erkalovic') # intro chapter c1 = epub.EpubHtml(title='Introduction', file_name='intro.xhtml', lang='hr') c1.content=u'
Introduction paragraph where i explain what is happening.
' # defube style style = '''BODY { text-align: justify;}''' default_css = epub.EpubItem(uid="style_default", file_name="style/default.css", media_type="text/css", content=style) book.add_item(default_css) # about chapter c2 = epub.EpubHtml(title='About this book', file_name='about.xhtml') c2.content='Helou, this is my book! There are many books, but this one is mine.
' c2.set_language('hr') c2.properties.append('rendition:layout-pre-paginated rendition:orientation-landscape rendition:spread-none') c2.add_item(default_css) # add chapters to the book book.add_item(c1) book.add_item(c2) # create table of contents # - add manual link # - add section # - add auto created links to chapters book.toc = (epub.Link('intro.xhtml', 'Introduction', 'intro'), (epub.Section('Languages'), (c1, c2)) ) # add navigation files book.add_item(epub.EpubNcx()) book.add_item(epub.EpubNav()) # define css style style = ''' @namespace epub "http://www.idpf.org/2007/ops"; body { font-family: Cambria, Liberation Serif, Bitstream Vera Serif, Georgia, Times, Times New Roman, serif; } h2 { text-align: left; text-transform: uppercase; font-weight: 200; } ol { list-style-type: none; } ol > li:first-child { margin-top: 0.3em; } nav[epub|type~='toc'] > ol > li > ol { list-style-type:square; } nav[epub|type~='toc'] > ol > li > ol > li { margin-top: 0.3em; } ''' # add css file nav_css = epub.EpubItem(uid="style_nav", file_name="style/nav.css", media_type="text/css", content=style) book.add_item(nav_css) # create spine book.spine = ['nav', c1, c2] # create epub file epub.write_epub('test.epub', book, {}) python-ebooklib-0.15~ds0.orig/samples/README.md 0000644 0001750 0001750 00000000624 12326461175 021124 0 ustar alessio alessio EbookLib Samples ================ * 01_sample_create Create simple EPUB with two chapters and custom CSS for the navigation. * 02_cover_create Same as 01_sample_create but with cover page. * 03_advanced_create Creates EPUB but uses some advanced options from the library. * 04_markdown_parse Simple script which creates static markdown files + images from your EPUB. * 05_plugins_create python-ebooklib-0.15~ds0.orig/samples/05_plugins_create/ 0000700 0001750 0001750 00000000000 12326462732 023141 5 ustar alessio alessio python-ebooklib-0.15~ds0.orig/samples/05_plugins_create/README.md 0000644 0001750 0001750 00000000121 12326461175 024424 0 ustar alessio alessio Plugins ======= How to make your useless plugin. ## Start python create.py python-ebooklib-0.15~ds0.orig/samples/05_plugins_create/create.py 0000644 0001750 0001750 00000005374 12326461175 025001 0 ustar alessio alessio # coding=utf-8 from ebooklib import epub from ebooklib.plugins.base import BasePlugin class SamplePlugin(BasePlugin): NAME = 'Sample Plugin' # Very useless but example of what can be done def html_before_write(self, book, chapter): from urlparse import urlparse, urljoin from lxml import html, etree utf8_parser = html.HTMLParser(encoding='utf-8') tree = html.document_fromstring(chapter.content, parser=utf8_parser) root = tree.getroottree() if len(root.find('body')) != 0: body = tree.find('body') for _link in body.xpath("//a[@class='test']"): _link.set('href', 'http://www.binarni.net/') chapter.content = etree.tostring(tree, pretty_print=True, encoding='utf-8') if __name__ == '__main__': book = epub.EpubBook() # add metadata book.set_identifier('sample123456') book.set_title('Sample book') book.set_language('en') book.add_author('Aleksandar Erkalovic') # intro chapter c1 = epub.EpubHtml(title='Introduction', file_name='intro.xhtml', lang='en') c1.content=u'Introduction paragraph with a link where i explain what is happening.
' # about chapter c2 = epub.EpubHtml(title='About this book', file_name='about.xhtml') c2.content='Helou, this is my book! There are many books, but this one is mine.
' # add chapters to the book book.add_item(c1) book.add_item(c2) # create table of contents # - add section # - add auto created links to chapters book.toc = (epub.Link('intro.xhtml', 'Introduction', 'intro'), (epub.Section('Languages'), (c1, c2)) ) # add navigation files book.add_item(epub.EpubNcx()) book.add_item(epub.EpubNav()) # define css style style = ''' @namespace epub "http://www.idpf.org/2007/ops"; body { font-family: Cambria, Liberation Serif, Bitstream Vera Serif, Georgia, Times, Times New Roman, serif; } h2 { text-align: left; text-transform: uppercase; font-weight: 200; } ol { list-style-type: none; } ol > li:first-child { margin-top: 0.3em; } nav[epub|type~='toc'] > ol > li > ol { list-style-type:square; } nav[epub|type~='toc'] > ol > li > ol > li { margin-top: 0.3em; } ''' # add css file nav_css = epub.EpubItem(uid="style_nav", file_name="style/nav.css", media_type="text/css", content=style) book.add_item(nav_css) # create spine book.spine = ['nav', c1, c2] opts = {'plugins': [SamplePlugin()]} # create epub file epub.writeEPUB('test.epub', book, opts) python-ebooklib-0.15~ds0.orig/samples/01_basic_create/ 0000700 0001750 0001750 00000000000 12326462732 022535 5 ustar alessio alessio python-ebooklib-0.15~ds0.orig/samples/01_basic_create/README.md 0000644 0001750 0001750 00000000121 12326461175 024020 0 ustar alessio alessio Basic create ============ Simple EPUB3 creation. ## Start python create.py python-ebooklib-0.15~ds0.orig/samples/01_basic_create/create.py 0000644 0001750 0001750 00000003655 12326461175 024375 0 ustar alessio alessio # coding=utf-8 from ebooklib import epub if __name__ == '__main__': book = epub.EpubBook() # add metadata book.set_identifier('sample123456') book.set_title('Sample book') book.set_language('en') book.add_author('Aleksandar Erkalovic') # intro chapter c1 = epub.EpubHtml(title='Introduction', file_name='intro.xhtml', lang='en') c1.content=u'Introduction paragraph where i explain what is happening.
' # about chapter c2 = epub.EpubHtml(title='About this book', file_name='about.xhtml') c2.content='Helou, this is my book! There are many books, but this one is mine.
' # add chapters to the book book.add_item(c1) book.add_item(c2) # create table of contents # - add section # - add auto created links to chapters book.toc = (epub.Link('intro.xhtml', 'Introduction', 'intro'), (epub.Section('Languages'), (c1, c2)) ) # add navigation files book.add_item(epub.EpubNcx()) book.add_item(epub.EpubNav()) # define css style style = ''' @namespace epub "http://www.idpf.org/2007/ops"; body { font-family: Cambria, Liberation Serif, Bitstream Vera Serif, Georgia, Times, Times New Roman, serif; } h2 { text-align: left; text-transform: uppercase; font-weight: 200; } ol { list-style-type: none; } ol > li:first-child { margin-top: 0.3em; } nav[epub|type~='toc'] > ol > li > ol { list-style-type:square; } nav[epub|type~='toc'] > ol > li > ol > li { margin-top: 0.3em; } ''' # add css file nav_css = epub.EpubItem(uid="style_nav", file_name="style/nav.css", media_type="text/css", content=style) book.add_item(nav_css) # create spine book.spine = ['nav', c1, c2] # create epub file epub.write_epub('test.epub', book, {}) python-ebooklib-0.15~ds0.orig/samples/02_cover_create/ 0000700 0001750 0001750 00000000000 12326462732 022573 5 ustar alessio alessio python-ebooklib-0.15~ds0.orig/samples/02_cover_create/README.md 0000644 0001750 0001750 00000000141 12326461175 024060 0 ustar alessio alessio Cover support ============= Create simple EPUB3 with cover page. ## Start python create.py python-ebooklib-0.15~ds0.orig/samples/02_cover_create/create.py 0000644 0001750 0001750 00000004157 12326461175 024431 0 ustar alessio alessio # coding=utf-8 from ebooklib import epub if __name__ == '__main__': book = epub.EpubBook() # add metadata book.set_identifier('sample123456') book.set_title('Sample book') book.set_language('en') book.add_author('Aleksandar Erkalovic') # add cover image book.set_cover("image.jpg", open('cover.jpg', 'r').read()) # intro chapter c1 = epub.EpubHtml(title='Introduction', file_name='intro.xhtml', lang='hr') c1.content=u'Introduction paragraph where i explain what is happening.
' # about chapter c2 = epub.EpubHtml(title='About this book', file_name='about.xhtml') c2.content='Helou, this is my book! There are many books, but this one is mine.