![]() |
#1 |
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Nov 2023
Device: pc
|
Welcome to follow my python-epub3 project
Hey guys
![]() Github: https://github.com/ChenyangGao/python-epub3 Documentation: https://python-epub3.readthedocs.io Pypi: https://pypi.org/project/python-epub3/ Install through github: Code:
pip install git+https://github.com/ChenyangGao/python-epub3 Code:
pip install python-epub3 Code:
>>> # Import the `python-epub3` module >>> from epub3 import ePub >>> # Create an e-book, which can accept an actual existing e-book path >>> book = ePub() >>> book <{http://www.idpf.org/2007/opf}package>{'version': '3.0', 'unique-identifier': 'BookId'} >>> # View metadata >>> book.metadata <{http://www.idpf.org/2007/opf}metadata> [<{http://purl.org/dc/elements/1.1/}identifier>{'id': 'BookId'} text='urn:uuid:d6cc8f4a-d489-47c9-8b69-97dd597e02c3', <{http://purl.org/dc/elements/1.1/}language> text='en', <{http://purl.org/dc/elements/1.1/}title>, <{http://www.idpf.org/2007/opf}meta>{'property': 'dcterms:modified'} text='2023-11-21T16:55:42Z'] >>> # Modify title, i.e. dc:title >>> book.title = "my book" >>> # Modify language, i.e. dc:language >>> book.language = "zh-CN" >>> # Update modification time >>> book.modified '2023-11-21T16:56:23Z' >>> # View metadata again >>> book.metadata <{http://www.idpf.org/2007/opf}metadata> [<{http://purl.org/dc/elements/1.1/}identifier>{'id': 'BookId'} text='urn:uuid:d6cc8f4a-d489-47c9-8b69-97dd597e02c3', <{http://purl.org/dc/elements/1.1/}language> text='zh-CN', <{http://purl.org/dc/elements/1.1/}title> text='my book', <{http://www.idpf.org/2007/opf}meta>{'property': 'dcterms:modified'} text='2023-11-21T16:56:23Z'] >>> # Add a href >>> item = book.manifest.add("index.xhtml") >>> item <Item({'id': '6053413d-b534-4409-9e9f-7a5cf0a74da9', 'href': 'index.xhtml', 'media-type': 'application/xhtml+xml'}) at 0x1066e75d0> >>> # Add the above file to spine >>> book.spine.add(item.id) <Itemref({'idref': '6053413d-b534-4409-9e9f-7a5cf0a74da9'}) at 0x1076de2d0> >>> # Open the above file and write some textual data >>> file = item.open("w") >>> file.write('''<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html> ... <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"> ... <head> ... <title></title> ... </head> ... <body> ... <p> </p> ... </body> ... </html>''') 211 >>> file.close() >>> # Add a href and associate it with an external path >>> item = book.manifest.add("cover.png", "/path/to/cover.png") >>> item <Item({'id': '35f19873-121d-42f9-9d56-e99cdac7d885', 'href': 'cover.png', 'media-type': 'image/png'}) at 0x1066f5850> >>> # Set cover >>> book.cover = item.id >>> book.cover '35f19873-121d-42f9-9d56-e99cdac7d885' >>> # Get <meta> metadata item through function >>> book.metadata.meta('[@name="cover"]') <{http://www.idpf.org/2007/opf}meta>{'name': 'cover', 'content': '35f19873-121d-42f9-9d56-e99cdac7d885'} >>> # Get <dc:name> metadata item through function >>> book.metadata.dc("title") <{http://purl.org/dc/elements/1.1/}title> text='my book' >>> # Pack and save the book >>> book.pack("book.epub") |
![]() |
![]() |
![]() |
#2 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,164
Karma: 18843349
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
Looks interesting. It might help answer those questions when people want to bulk-edit their library.
|
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Nov 2023
Device: pc
|
Quote:
|
|
![]() |
![]() |
![]() |
#4 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,164
Karma: 18843349
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
nice!
Do you have access to the individual xhtml/image/css/ncz files so you can read the text into a variable and manipulate with soup/re/etc.??? |
![]() |
![]() |
![]() |
#5 | |
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Nov 2023
Device: pc
|
Quote:
# read text data text = book.manifest.open("index.xhtml").read() # read binary data data = book.manifest.open("cover.png", "rb").read() Additionally, you can open any of the files in the epub and it will return a file object. You can directly manipulate this file object. If you only change one byte, it will actually change one byte, which is very beneficial for handling very large files. |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,087
Karma: 5450184
Join Date: Nov 2009
Device: many
|
How are epub3 refines on metadata handled?
|
![]() |
![]() |
![]() |
#7 |
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Nov 2023
Device: pc
|
|
![]() |
![]() |
![]() |
#8 |
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Nov 2023
Device: pc
|
I am also a long-term user of Sigil. For example, I have developed a console plugin for Sigil. You can find the documentation for it at https://sigil-console.readthedocs.io/en/latest/. I will update the documentation to English soon.
|
![]() |
![]() |
![]() |
#9 |
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Nov 2023
Device: pc
|
EPUB 3 introduces several key improvements in metadata processing over EPUB 2. Some of the notable improvements include:
1. Enhanced Semantic Markup: EPUB 3 allows for richer semantic markup through the use of HTML5 and other technologies, enabling better structuring and labeling of content, which in turn enhances the metadata processing capabilities. 2. Richer Metadata Support: EPUB 3 provides support for a wider range of metadata properties, including those defined in the Dublin Core Metadata Initiative (DCMI) and other metadata schemas, allowing for more comprehensive and detailed descriptions of publications. 3. Accessibility Metadata: EPUB 3 includes improved support for accessibility metadata, making it easier to provide essential information about accessibility features and requirements for readers with disabilities. 4. Global Language Support: EPUB 3 offers enhanced support for multilingual publications, allowing for more robust representation of metadata in various languages and scripts. 5. Media Overlays Metadata: EPUB 3 introduces support for media overlays, enabling synchronization of audio and text elements, and includes specific metadata for defining and managing these overlays. 6. Linking and Navigation Improvements: EPUB 3 includes enhancements to linking and navigation within publications, providing better ways to express relationships between different parts of the content, which can be reflected in the metadata. Overall, EPUB 3's improvements in metadata processing contribute to a more flexible, versatile, and standardized approach to describing and organizing publication metadata, offering benefits for both content creators and end users. |
![]() |
![]() |
![]() |
#10 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,087
Karma: 5450184
Join Date: Nov 2009
Device: many
|
No, I am referring to the epub3 metadata "refines" attribute that allows additional metadata to be added and associated with other metadata to refine its meaning.
See for example: https://www.w3.org/TR/epub-33/#sec-pkg-metadata Specifically Section 5.3.6 The refines Attribute. |
![]() |
![]() |
![]() |
#11 |
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Nov 2023
Device: pc
|
I currently haven't added any specific support for 'refine', but in my module, all XML information is preserved. You may need to determine it yourself for now. I have seen examples of using 'refine' like this:
http://docs.sourcefabric.org/project...ook.add_author But I haven't decided yet whether to provide dedicated support for it. |
![]() |
![]() |
![]() |
Tags |
epub, epub3, python |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
epub3 app with epub3 dictionary support | Doitsu | ePub | 0 | 01-21-2017 09:38 AM |
Project Management Advice and Tips: How Good Project Managers Manage Project | amazon author | Self-Promotions by Authors and Publishers | 0 | 04-07-2015 04:04 AM |
Another EPub3/2 generator with single python file | tkirke | ePub | 1 | 10-24-2012 03:57 PM |
Python Gutenberg E-text Project: PyGE | ignatz | Deals and Resources (No Self-Promotion or Affiliate Links) | 2 | 09-17-2004 01:18 PM |