使用 SDK 以编程方式将转换后的视频添加到 iTunes
我编写了一些简单的代码,与 HandbrakeCLI 交互,将视频转换为 iTunes 可以处理的格式。完成后,我希望它自动添加到 iTunes。
据我从 iTunes SDK 文档中得知,以下 VBScript 代码应该可以工作:
Option Explicit
Dim oiTunes
Set oiTunes = CreateObject("iTunes.Application")
oiTunes.ConvertFile2("D:\Development\VBScript\converted-video.avi")
Set oiTunes = Nothing
Msgbox "Uploaded!"
但是,在运行时,“已上传!”出现消息,但 iTunes 尚未导入(或什至开始导入)任何视频文件。
谁能建议我如何让它发挥作用?此外,如果有人可以向我展示如何确定它是否已完成导入(因为我想在导入完成后重命名元数据),那么我将非常感激。
I've written some simple code which interfaces with HandbrakeCLI to convert a video into a format that iTunes can handle. Once that has finished, I want it to be automatically added to iTunes.
From what I can tell from the iTunes SDK documentation, the following VBScript code should work:
Option Explicit
Dim oiTunes
Set oiTunes = CreateObject("iTunes.Application")
oiTunes.ConvertFile2("D:\Development\VBScript\converted-video.avi")
Set oiTunes = Nothing
Msgbox "Uploaded!"
However, upon running, the "Uploaded!" message appears but iTunes has not imported (or even started to import) any video file.
Can anyone suggest how I can get this working? In addition, if someone can show me how I can also determine whether or not it has finished the import (as I'd like to rename the meta-data once the import has finished) then I'd really appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎
oiTunes.ConvertFile2
是一个返回“转换”对象的方法。可能它正在异步转换文件,因此您可以同时执行其他 VBScript 代码。但是,您的代码直接终止了 oiTunes 对象,也终止了转换进程。似乎有两个属性可以用来读取转换的状态:
.ProgressValue
和.MaxProgressValue
。因此,您可以创建一个循环,例如:我现在没有 iTunes,因此我无法验证这是否能解决您的问题,但我希望这能推动您朝着正确的方向前进。
It seems that
oiTunes.ConvertFile2
is a method that returns an 'convert' object. Probably it is converting the file asynchronic, so you can execute other VBScript code in the mean time. However, your code directly kills the oiTunes object, also killing the convert process.There seems to be two properties you can use to read the status of the convertion:
.ProgressValue
and.MaxProgressValue
. So you can create a loop like:I do not have iTunes right now, so I couldn't verify if this will solve you problems, but I hope this is giving you a push in the right direction.
遵循 AutomatedChaos 的有用指示,我提供了以下工作代码示例:
确保您可以首先通过 iTunes UI 导入视频文件,因为如果不能,那么导入将会失败。
尝试将任何内容放入
Do .. Loop
中没有什么意义,因为一个 44 分钟的视频在大约 2 秒内就添加到了我的(相当低的规格)计算机上。Following the useful pointer by AutomatedChaos, I offer the following working code sample:
Make sure that you can import the video file through the iTunes UI first, because if you can't then this will fail.
There is little point trying to put anything into the
Do .. Loop
as a 44 minute video is added on my (reasonably low specification) computer in about 2 seconds.