Permute
Permute 是一款 macOS 媒体转换工具。Protocol Launcher 允许您生成 Permute URL scheme 链接。
使用
有两种方式使用此库:
- 按需从子路径导入,支持 tree-shaking,让打包体积更小。
- 从根包全量导入更适合快速脚本或演示,但会包含所有应用模块。
生产构建建议使用按需导入;快速脚本或 demo 可以使用全量导入。
选择安装方式
按需加载
推荐使用。生产环境优化。
全量导入
使用便捷。适合快速脚本。
URL 方法
Charlie Monroe Software 官方文档说明了用于高级工作流的 permute:// scheme。本模块只暴露官方记录的 convert 和 stitch 动作,以及官方记录的查询参数。
Convert
生成使用 convert 动作把文件加入 Permute 的 permute:// URL。preset 请使用 Permute 中可见的预设名称。
ts
import { convert } from 'protocol-launcher/permute'
const url = convert({
filePath: '/Users/example/Downloads/file.mp4',
preset: 'MP4',
source: 'MyScript',
})
const urlWithOptions = convert({
filePath: '/Users/example/Downloads/source file.mp4',
preset: 'MP4',
callback: 'myapp://7452d66e-9260-43f0-97cb-d0467a1143a7',
destination: '/Users/example/Movies/Converted',
custom_group: 'Batch 1',
trim: '10:90',
crop: '0;0;1280;720',
})Stitch
生成添加拼接转换的 permute:// URL。Permute 要求提供包含所有输入文件的文件夹路径、拼接输出文件名 name,以及从 files 数组生成的编号文件参数。
ts
import { stitch } from 'protocol-launcher/permute'
const url = stitch({
folderPath: '/Users/example/Downloads/',
preset: 'MP4',
source: 'MyScript',
name: 'foo.mp4',
files: ['File1.mp4', 'File2.mp4'],
})生成的 URL
ts
convert({
filePath: '/Users/example/Downloads/file.mp4',
preset: 'MP4',
source: 'MyScript',
})
// => 'permute:///Users/example/Downloads/file.mp4?action=convert&preset=MP4&source=MyScript'
convert({
filePath: '/Users/example/Downloads/source file.mp4',
preset: 'MP4',
callback: 'myapp://7452d66e-9260-43f0-97cb-d0467a1143a7',
destination: '/Users/example/Movies/Converted',
custom_group: 'Batch 1',
trim: '10:90',
crop: '0;0;1280;720',
})
// => 'permute:///Users/example/Downloads/source%20file.mp4?action=convert&preset=MP4&callback=myapp%3A%2F%2F7452d66e-9260-43f0-97cb-d0467a1143a7&destination=%2FUsers%2Fexample%2FMovies%2FConverted&custom_group=Batch%201&trim=10%3A90&crop=0%3B0%3B1280%3B720'
stitch({
folderPath: '/Users/example/Downloads/',
preset: 'MP4',
source: 'MyScript',
name: 'foo.mp4',
files: ['File1.mp4', 'File2.mp4'],
})
// => 'permute:///Users/example/Downloads/?action=stitch&preset=MP4&source=MyScript&name=foo.mp4&file1=File1.mp4&file2=File2.mp4'查询参数
preset是要使用的 Permute 预设名称。source是可选参数,Permute 会用它对转换任务分组。callback是可选参数;转换结束后 Permute 会异步打开该回调 URL。destination是可选输出文件夹路径。remove_original: true会生成remove_original=true,请求 Permute 在完成后把输入文件移到废纸篓。custom_group会生成官方文档中的custom_group参数。trim使用 Permute 的start:stop秒数格式,例如:10、10:或10:90。crop使用 Permute 的x;y;width;height矩形格式。