文章目录
- 关于 epub2txt
- 安装
- 命令行使用
- 查看 options
- 常见用法
- 示例1
- Python 代码调用
- manual
- absl.app:
- absl.logging:
- epub2txt.__main__:
- absl.flags:
关于 epub2txt
Convert epub file to txt
- github : https://github.com/ffreemt/epub2txt
安装
pip install epub2txt
命令行使用
查看 options
epub2txt --helpfull
输出较多,见文末
常见用法
# convert test.epub to test.txt
epub2txt -f test.epub
# browse for epub file, txt file will be in the same directory as the epub file
epub2txt
# show epub book info: title and toc
epub2txt -i
# show more epub book info: title, toc, metadata, spine (list of stuff packed into the epub)
epub2txt -m
# show epub2txt version
epub2txt -V
示例1
epub2txt -i
终端输入以下命令,系统将弹出文件夹,让用户选择 文件;然后产生结果如下:
晨间日记的奇迹(精排版)
[('封面', 'text00000.html'),
('作者序', 'text00002.html'),
('给所有台湾的心灵之友们', 'text00003.html'),
...
('参考文献', 'text00077.html'),
('结\t语', 'text00078.html')]
Python 代码调用
from epub2txt import epub2txt
# 从网络 epub 转换
url = "https://github.com/ffreemt/tmx2epub/raw/master/tests/1.tmx.epub"
res = epub2txt(url) # res 为字符串类型
# 从本地 epub 文件
filepath = r"tests\test.epub"
res = epub2txt(filepath)
# output as a list of chapters
ch_list = epub2txt(filepath, outputlist=True)
# chapter titles will be available as epub2txt.content_titles if available
# 一个章节作为 输出list 的一个 item,效果如下
manual
epub2txt --helpfull
USAGE: /Users/xx/miniconda3/bin/epub2txt [flags]
flags:
absl.app:
-
-?
,--[no]help
: show this help
(default: ‘false’) -
--[no]helpfull
: show full help
(default: ‘false’) -
--[no]helpshort
: show this help
(default: ‘false’) -
--[no]helpxml
: like --helpfull, but generates XML output
(default: ‘false’) -
--[no]only_check_args
: Set to true to validate args and exit.
(default: ‘false’) -
--[no]pdb
: Alias for --pdb_post_mortem.
(default: ‘false’) -
--[no]pdb_post_mortem
: Set to true to handle uncaught exceptions with PDB post mortem.
(default: ‘false’) -
--profile_file
: Dump profile information to a file (for python -m pstats). Implies --run_with_profiling. -
--[no]run_with_pdb
: Set to true for PDB debug mode
(default: ‘false’) -
--[no]run_with_profiling
: Set to true for profiling the script. Execution will be slower, and the output format might change over time.
(default: ‘false’) -
--[no]use_cprofile_for_profiling
: Use cProfile instead of the profile module for profiling. This has no effect unless --run_with_profiling is set.
(default: ‘true’)
absl.logging:
--[no]alsologtostderr
: also log to stderr?
(default: ‘false’)--log_dir
: directory to write logfiles into
(default: ‘’)--logger_levels
: Specify log level of loggers. The format is a CSV list ofname:level
. Wherename
is the logger name used withlogging.getLogger()
, andlevel
is a level name (INFO, DEBUG, etc). e.g.myapp.foo:INFO,other.logger:DEBUG
(default: ‘’)--[no]logtostderr
: Should only log to stderr?
(default: ‘false’)--[no]showprefixforinfo
: If False, do not prepend prefix to info messages when it’s logged to stderr, --verbosity is set to INFO level, and python logging is used.
(default: ‘true’)--stderrthreshold
: log messages at this level, or more severe, to stderr in addition to the logfile. Possible values are ‘debug’, ‘info’, ‘warning’, ‘error’, and ‘fatal’. Obsoletes --alsologtostderr. Using --alsologtostderr cancels the effect of this flag. Please also note that this flag is subject to --verbosity and requires logfile not be stderr.
(default: ‘fatal’)-v,--verbosity
: Logging verbosity level. Messages logged at this level or lower will be included. Set to 1 for debug logging. If the flag was not set or supplied, the value will be changed from the default of -1 (warning) to 0 (info) after flags are parsed.
(default: ‘-1’)
(an integer)
epub2txt.main:
--[no]debug
: print verbose debug messages
(default: ‘false’)-d,--dest
: destintioin folder to save the epub file, if left empty, set to the same folder where tmx file is located
(default: ‘’)-m,--[no]detailed-info
: print more detailed book info and exit
(default: ‘false’)-f,--filename
: tmx filename (can be gzip or bz2)
(default: ‘’)-i,--[no]info
: print book info and exit
(default: ‘false’)-V,--[no]version
: print version and exit
(default: ‘false’)
absl.flags:
--flagfile
: Insert flag definitions from the given file into the command line.
(default: ‘’)--undefok
: comma-separated list of flag names that it is okay to specify on the command line even if the program does not define a flag with that name. IMPORTANT`: flags in this list that have arguments MUST use the --flag=value format.
(default: ‘’)
2024-03-24(日)