ebooklib Package¶
ebooklib
Package¶
epub
Module¶
- class ebooklib.epub.EpubBook[source]¶
Bases:
object
- add_item(item)[source]¶
Add additional item to the book. If not defined, media type and chapter id will be defined for the item.
- Args:
item: Item instance
- add_prefix(name, uri)[source]¶
Appends custom prefix to be added to the content.opf document
>>> epub_book.add_prefix('bkterms', 'http://booktype.org/')
- Args:
name: namespave name
uri: URI for the namespace
- get_item_with_href(href)[source]¶
Returns item for defined HREF.
>>> book.get_item_with_href('EPUB/document.xhtml')
- Args:
href: HREF for the item we are searching for
- Returns:
Returns item object. Returns None if nothing was found.
- get_item_with_id(uid)[source]¶
Returns item for defined UID.
>>> book.get_item_with_id('image_001')
- Args:
uid: UID for the item
- Returns:
Returns item object. Returns None if nothing was found.
- get_items_of_media_type(media_type)[source]¶
Returns all items of specified media type.
- Args:
media_type: Media type for items we are searching for
- Returns:
Returns found items as tuple.
- get_items_of_type(item_type)[source]¶
Returns all items of specified type.
>>> book.get_items_of_type(epub.ITEM_IMAGE)
- Args:
item_type: Type for items we are searching for
- Returns:
Returns found items as tuple.
- get_template(name)[source]¶
Returns value for the template.
- Args:
name: template name
- Returns:
Value of the template.
- set_cover(file_name, content, create_page=True)[source]¶
Set cover and create cover document if needed.
- Args:
file_name: file name of the cover page
content: Content for the cover image
create_page: Should cover page be defined. Defined as bool value (optional). Default value is True.
- set_identifier(uid)[source]¶
Sets unique id for this epub
- Args:
uid: Value of unique identifier for this book
- set_language(lang)[source]¶
Set language for this epub. You can set multiple languages. Specific items in the book can have different language settings.
- Args:
lang: Language code
- set_template(name, value)[source]¶
Defines templates which are used to generate certain types of pages. When defining new value for the template we have to use content of type ‘str’ (Python 2) or ‘bytes’ (Python 3).
- At the moment we use these templates:
ncx
nav
chapter
cover
- Args:
name: Name for the template
value: Content for the template
- class ebooklib.epub.EpubCover(uid='cover-img', file_name='')[source]¶
Bases:
EpubItem
Represents Cover image in the EPUB file.
- get_type()[source]¶
Guess type according to the file extension. Might not be the best way how to do it, but it works for now.
- Items can be of type:
ITEM_UNKNOWN = 0
ITEM_IMAGE = 1
ITEM_STYLE = 2
ITEM_SCRIPT = 3
ITEM_NAVIGATION = 4
ITEM_VECTOR = 5
ITEM_FONT = 6
ITEM_VIDEO = 7
ITEM_AUDIO = 8
ITEM_DOCUMENT = 9
ITEM_COVER = 10
We map type according to the extensions which are defined in ebooklib.EXTENSIONS.
- Returns:
Returns type of the item as number.
- class ebooklib.epub.EpubCoverHtml(uid='cover', file_name='cover.xhtml', image_name='', title='Cover')[source]¶
Bases:
EpubHtml
Represents Cover page in the EPUB file.
- class ebooklib.epub.EpubHtml(uid=None, file_name='', media_type='', content=None, title='', lang=None, direction=None, media_overlay=None, media_duration=None)[source]¶
Bases:
EpubItem
Represents HTML document in the EPUB file.
- add_item(item)[source]¶
Add other item to this document. It will create additional links according to the item type.
- Args:
item: item we want to add defined as instance of EpubItem
- add_link(**kwgs)[source]¶
Add additional link to the document. Links will be embeded only inside of this document.
>>> add_link(href='styles.css', rel='stylesheet', type='text/css')
- get_body_content()[source]¶
Returns content of BODY element for this HTML document. Content will be of type ‘str’ (Python 2) or ‘bytes’ (Python 3).
- Returns:
Returns content of this document.
- get_content(default=None)[source]¶
Returns content for this document as HTML string. Content will be of type ‘str’ (Python 2) or ‘bytes’ (Python 3).
- Args:
default: Default value for the content if it is not defined.
- Returns:
Returns content of this document.
- get_language()[source]¶
Get language code for this book item. Language of the book item can be different from the language settings defined globaly for book.
- Returns:
As string returns language code.
- get_links()[source]¶
Returns list of additional links defined for this document.
- Returns:
As tuple return list of links.
- get_links_of_type(link_type)[source]¶
Returns list of additional links of specific type.
- Returns:
As tuple returns list of links.
- class ebooklib.epub.EpubImage(*args, **kwargs)[source]¶
Bases:
EpubItem
Represents Image in the EPUB file.
- get_type()[source]¶
Guess type according to the file extension. Might not be the best way how to do it, but it works for now.
- Items can be of type:
ITEM_UNKNOWN = 0
ITEM_IMAGE = 1
ITEM_STYLE = 2
ITEM_SCRIPT = 3
ITEM_NAVIGATION = 4
ITEM_VECTOR = 5
ITEM_FONT = 6
ITEM_VIDEO = 7
ITEM_AUDIO = 8
ITEM_DOCUMENT = 9
ITEM_COVER = 10
We map type according to the extensions which are defined in ebooklib.EXTENSIONS.
- Returns:
Returns type of the item as number.
- class ebooklib.epub.EpubItem(uid=None, file_name='', media_type='', content=b'', manifest=True)[source]¶
Bases:
object
Base class for the items in a book.
- get_content(default=b'')[source]¶
Returns content of the item. Content should be of type ‘str’ (Python 2) or ‘bytes’ (Python 3)
- Args:
default: Default value for the content if it is not already defined.
- Returns:
Returns content of the item.
- get_name()[source]¶
Returns name for this item. By default it is always file name but it does not have to be.
- Returns:
Returns file name for this item.
- get_type()[source]¶
Guess type according to the file extension. Might not be the best way how to do it, but it works for now.
- Items can be of type:
ITEM_UNKNOWN = 0
ITEM_IMAGE = 1
ITEM_STYLE = 2
ITEM_SCRIPT = 3
ITEM_NAVIGATION = 4
ITEM_VECTOR = 5
ITEM_FONT = 6
ITEM_VIDEO = 7
ITEM_AUDIO = 8
ITEM_DOCUMENT = 9
ITEM_COVER = 10
We map type according to the extensions which are defined in ebooklib.EXTENSIONS.
- Returns:
Returns type of the item as number.
Bases:
EpubHtml
Represents Navigation Document in the EPUB file.
Returns if this document is chapter or not.
- Returns:
Returns book value.
- class ebooklib.epub.EpubNcx(uid='ncx', file_name='toc.ncx')[source]¶
Bases:
EpubItem
Represents Navigation Control File (NCX) in the EPUB.
- class ebooklib.epub.EpubReader(epub_file_name, options=None)[source]¶
Bases:
object
- DEFAULT_OPTIONS = {'ignore_ncx': False}¶
- class ebooklib.epub.EpubSMIL(uid=None, file_name='', content=None)[source]¶
Bases:
EpubItem
- get_type()[source]¶
Guess type according to the file extension. Might not be the best way how to do it, but it works for now.
- Items can be of type:
ITEM_UNKNOWN = 0
ITEM_IMAGE = 1
ITEM_STYLE = 2
ITEM_SCRIPT = 3
ITEM_NAVIGATION = 4
ITEM_VECTOR = 5
ITEM_FONT = 6
ITEM_VIDEO = 7
ITEM_AUDIO = 8
ITEM_DOCUMENT = 9
ITEM_COVER = 10
We map type according to the extensions which are defined in ebooklib.EXTENSIONS.
- Returns:
Returns type of the item as number.
- class ebooklib.epub.EpubWriter(name, book, options=None)[source]¶
Bases:
object
- DEFAULT_OPTIONS = {'epub2_guide': True, 'epub3_landmark': True, 'epub3_pages': True, 'landmark_title': 'Guide', 'package_direction': False, 'pages_title': 'Pages', 'play_order': {'enabled': False, 'start_from': 1}, 'spine_direction': True}¶