用于操作苹果Keynote演示文件的工具。
项目描述
keynote-parser
keynote-parser
是一个Python模块,用于解包和重新打包 苹果Keynote .key
文件。它支持由Keynote版本12.2.1(截至2022年12月)生成的Keynote文件。
Keynote使用专有、压缩的二进制格式来存储其演示文稿。此格式包含一个包含图像和视频的zip文件,以及包含元数据、文本以及演示文稿中使用的所有其他定义的Snappy压缩 Protobuf .iwa
文件。
keynote-parser
将这些组件文件解包到目录中的 .yaml
文件中,使其可以通过文本编辑器或脚本进行编辑,然后允许将这些文件重新打包成一个可用的Keynote存档。
你可以用它做什么?嗯,我使用它来允许在Git中为Keynote文件进行版本控制,这使得差异更易于理解(而不是二进制),以及在外部脚本的响应下修改Keynote文件中的文本。(例如:在演示之前从数据库中更新的图表)
安装
pip3 install keynote-parser
用法
# Unpack MyPresentation.key into ./MyPresentation/
keynote-parser unpack MyPresentation.key
# Re-pack ./MyPresentation/ into MyPresentation.out.key
keynote-parser pack ./MyPresentation/
# List the files within a Keynote archive
keynote-parser ls MyPresentation.key
# Dump a particular .iwa file into its yaml representation on stdout
keynote-parser cat MyPresentation.key /Index/Slide-00001.iwa
# Replace text within a Keynote file in-place
keynote-parser replace MyPresentation.key --find "hello world" --replace "hello dolly"
格式
keynote-parser
支持从作为 --replacements
传入的JSON文件中读取替换列表。此文件必须具有以下形式
{
"replacements": [
{
"find": "regexp to search for",
"replace": "string to replace with"
},
...
]
}
此参数可以传递给keynote-parser replace
,以在Keynote文件中就地替换文本。它也可以传递给keynote-parser pack
,将目录打包到Keynote文件中,并在过程中替换文本。
替换图片
可以使用replacements
JSON格式在Keynote文件中替换图片。要这样做
- 使用
keynote-parser ls
命令确定要替换的图片名称。 - 将
find
模式设置为图片的名称,删除-\d\d\d
后缀。 - 将
replace
字段设置为替换图片的本地路径。
keynote-parser
会自动调整替换图片的大小,以适应目标图片的所有大小。
兼容性
请注意,在Keynote 10.2和Keynote 11.2之间,Keynote使用的许多Protobuf定义已经更改名称。keynote-parser
尚不支持向下兼容:它只能以当前支持的Keynote版本读取.key
文件,并将输出写入.yaml
,键与当前键的名称匹配。这意味着,使用较旧版本的keynote-parser
生成的.yaml
文件可能无法由v1.11.2.1或更高版本的keynote-parser
读取。
在解决这个问题之前(如果它被修复的话)- 为了正确读取较旧版本的keynote-parser
创建的.yaml
文件
- 使用较旧版本的
keynote-parser
读取文件 - 使用该旧版本写入一个
.key
(或.iwa
)文件 - 升级
keynote-parser
- 在新版本的
keynote-parser
中读取该结果.iwa
文件
更新
由于keynote-parser
包含从Keynote副本中提取的Protobuf定义,因此Keynote的新版本不可避免地会创建.key
文件,该文件无法由keynote-parser
读取。随着Keynote新版本的发布,可以通过在已安装Keynote的macOS机器上运行以下命令自动更新keynote-parser
:
# protobuf>=3.20.0rc1 must be installed, with the C++ runtime
# on Intel, this can be done with "pip install 'protobuf>=3.20.0rc1'"
# on Apple Silicon, this may require a manual build from source
cd dumper
make clean
make
故障排除
由于找不到snappy-c.h,无法完成安装。
snappy/snappymodule.cc:31:10: fatal error: 'snappy-c.h' file not found
这意味着您缺少Snappy库。使用操作系统支持的方法安装Snappy。例如,brew install snappy
,sudo apt-get install libsnappy-dev
等。
致谢
keynote-parser
是由Peter Sobot构建的,但主要基于之前的工作,由Sean Patrick O'Brien完成。O'Brien的格式文档副本包含在docs
文件夹中。
许可证
此存储库中的所有代码均根据MIT许可协议许可。
Copyright 2019-2022 Peter Sobot
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定要选择哪个,请了解更多关于安装软件包的信息。
源代码分发
构建分发
keynote-parser-1.13.1.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a8ca27b47affeda30ebcb8938875ce0d98bf235d6ef1595806164004710c47fe |
|
MD5 | 315b6611a302c8d8130d1fba0a81ffe3 |
|
BLAKE2b-256 | 065b48e7cafa08dee69a028427be6fb62d3078d1d5e34715e81959c2436516a7 |
keynote_parser-1.13.1.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | cf95124ae28f3282798064907e15d05714226b31cdeb2b9231bf1377dd29b076 |
|
MD5 | 643c9f103df0116bc8c499dec04e3a85 |
|
BLAKE2b-256 | c88e4f2dd0bb294621fcb32d8f5ff09ea1f58c03a17d898b983886e297ea7449 |