使用 SDK 以编程方式将转换后的视频添加到 iTunes

发布于 2024-10-19 08:38:41 字数 485 浏览 2 评论 0原文

我编写了一些简单的代码,与 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

屌丝范 2024-10-26 08:38:41

似乎 oiTunes.ConvertFile2 是一个返回“转换”对象的方法。可能它正在异步转换文件,因此您可以同时执行其他 VBScript 代码。但是,您的代码直接终止了 oiTunes 对象,也终止了转换进程。
似乎有两个属性可以用来读取转换的状态:.ProgressValue.MaxProgressValue。因此,您可以创建一个循环,例如:

Dim oConvert : Set oConvert = oiTunes.ConvertFile2(...)
Do : Loop while oConvert.ProgressValue < oConvert.MaxProgressValue
Set oConvert = Nothing
Set oiTunes = Nothing
MsgBox "Uploaded!"

我现在没有 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:

Dim oConvert : Set oConvert = oiTunes.ConvertFile2(...)
Do : Loop while oConvert.ProgressValue < oConvert.MaxProgressValue
Set oConvert = Nothing
Set oiTunes = Nothing
MsgBox "Uploaded!"

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.

好听的两个字的网名 2024-10-26 08:38:41

遵循 AutomatedChaos 的有用指示,我提供了以下工作代码示例:

Option Explicit
Dim oiTunes, oTracks, oAdd
Set oiTunes = CreateObject("iTunes.Application")
Set oTracks = oiTunes.LibraryPlaylist
Set oAdd = oTracks.AddFile("D:\Development\VBScript\converted-video.mp4")
Do : Loop While oAdd.InProgress = True
Set oAdd = Nothing
Set oTracks = Nothing
Set oiTunes = Nothing
Msgbox "Uploaded!"

确保您可以首先通过 iTunes UI 导入视频文件,因为如果不能,那么导入将会失败。

尝试将任何内容放入 Do .. Loop 中没有什么意义,因为一个 44 分钟的视频在大约 2 秒内就添加到了我的(相当低的规格)计算机上。

Following the useful pointer by AutomatedChaos, I offer the following working code sample:

Option Explicit
Dim oiTunes, oTracks, oAdd
Set oiTunes = CreateObject("iTunes.Application")
Set oTracks = oiTunes.LibraryPlaylist
Set oAdd = oTracks.AddFile("D:\Development\VBScript\converted-video.mp4")
Do : Loop While oAdd.InProgress = True
Set oAdd = Nothing
Set oTracks = Nothing
Set oiTunes = Nothing
Msgbox "Uploaded!"

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文