python epub库_Python epubfile包_程序模块 - PyPI - Python中文网

epubfileimportepubfilebook=epubfile.Epub.open('mybook.epub')fortext_idinbook.get_texts():soup=book.read_file(text_id,soup=True)...book.write_file(text_id,soup)forimage_idinbook.get_images():data=book.read_file(image_id)...book.write_file(image_id,data)# Note that this does not reverse the table of contents.book.set_spine_order(reversed(book.get_spine_order()))cover_id=book.get_cover_image()ifcover_id:book.rename_file(cover_id,'myfavoritecoverimage')book.save('modifiedbook.epub')

epubfile提供对epub书籍的简单编辑。epubfile尝试将文件修改保持在最低限度。它不会添加、删除或重新排列文件,除非您要求它这样做,并且不会插入其他元数据。因此,它对epub2和epub3都是有效的,前提是您坚持支持书籍版本的操作。

命令行实用程序

这个图书馆是出于我自己的需要而诞生的。所以有一些内置的实用程序。addfile:

Add files into the book.

covercomesfirst:

Rename the cover image file so that it is the alphabetically-first image.

merge:

Merge multiple books into one.

normalize:

Rename files and directories in the book to match a common structure.

规格符合性

epubfile没有严格执行epub规范,您可以使用它创建不符合规范的书籍。检查基本错误,我对有关如何提高规范遵守的问题和评论开放,而不给图书馆增加显著的大小或复杂性。我把简单性和易用性放在首位,而不是完美。

与……

对于高级的文件间操作和更好的验证,我建议将此库与一个好的编辑器(如Sigil)结合使用。我编写这个库是因为尽管sigil插件非常适合处理一本书,但是很难使用sigil来处理多本书、读取书籍数据以便在其他程序中使用,或者执行其他书籍间操作。

不可期待的

除了一些基本的getter和setter之外,我不打算实现图书元数据的对象模型。您可以完全控制Epub.opf美化组对象,以便可以根据需要编辑元数据。BSD 3-Clause License

Copyright (c) 2019, Ethan Dalool

https://github.com/voussoir/epubfile

All rights reserved.

Redistribution and use in source and binary forms, with or without

modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this

list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,

this list of conditions and the following disclaimer in the documentation

and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its

contributors may be used to endorse or promote products derived from

this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"

AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE

FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL

DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR

SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER

CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,

OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

欢迎加入QQ群-->: 979659372

group.png

推荐PyPI第三方库

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值