跳转到主要内容

用于操作苹果Keynote演示文件的工具。

项目描述

keynote-parser

build:

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 snappysudo 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 (182.6 kB 查看哈希值)

上传时间 源代码

构建分发

keynote_parser-1.13.1.0-py3-none-any.whl (203.3 kB 查看哈希值)

上传时间 Python 3

支持者

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误日志StatusPageStatusPage状态页面