如何以编程方式将 QuickTime 影片元数据属性从一种类型转换为另一种类型

如何以编程方式将 QuickTime 影片元数据属性从一种类型转换为另一种类型

我有大约 1,700 个 QuickTime 电影文件(一些带有 .mov 扩展名,大多数没有;这并不重要,所有文件都被系统视为“QuickTime 电影”,这就是它们的本质)存储在一个有组织的文件夹结构中。

使用 QuickTime Pro 7,我可以查看文件的属性并查看一组元数据,它称之为“注释”。其中一个注释是“作者”标签。我需要将该注释翻转为“艺术家”标签,同时保留其中的数据。

QuickTime Pro 属性

...针对这 1,700 多个文件。

实现自动化的最佳选项和实施方案是什么?

我的直觉是可以轻松设计一个 AppleScript,只需遍历此文件夹结构的内容即可查找此类型的文件,然后进行切换,但我的 AppleScript-fu 并不好。

答案1

好吧,我设法想出了一个办法(阅读:肮脏的黑客)来实现我想要的。我使用了 AppleScript 和 UI 脚本,通过西库利。它可以而且应该得到很大改进,比如,增加错误检查和容错功能。我基本上不得不在它经历整个过程时照顾它,因为每隔几十个文件它就会被什么东西卡住。话虽如此,它满足了我的目的并实现了我的目标。

global theCount

set theCount to 0 as number

tell application "Finder"
    set theFolder to choose folder with prompt "Select a directory:"
    display dialog "This script will open each QuickTime movie file contained within this folder and its subfolders in QuickTime Player 7, and change the Author attribute to an Artist attribute using the Sikuli IDE. Proceed?"
    my processFiles(theFolder)
    display dialog (theCount as string) & " files processed."
end tell

on processFiles(theFolder)
    tell application "System Events"
        set theItems to get the name of every disk item of theFolder
    end tell
    set theFolder to theFolder as string --do this to concatenate with item name in loop
    repeat with i from 1 to length of theItems --this is the loop that works on each file in the current folder
        set theItem to item i of theItems
        set theItem to (theFolder & theItem) as alias --get a file object
        set itemInfo to info for theItem --get the file's info
        if visible of itemInfo is true then --only work on invisibles
            if folder of itemInfo is false then --and check for folders first or next line will fail
                if type identifier of itemInfo is "com.apple.quicktime-movie" then
                    try --makes this more fault-tolerant
                        tell application "QuickTime Player 7"
                            open theItem
                        end tell
                        set theCount to theCount + 1
                        do shell script "java -jar /Applications/Sikuli-IDE.app/Contents/Resources/Java/sikuli-script.jar /Users/username/Desktop/flip\\ to\\ artist\\ source.sikuli" --Sikuli has a better command line interface, but it wasn't working on the current build. This is connecting directly to its java executable, and is REALLY slow as a result.
                    end try
                end if
            else if folder of itemInfo is true then
                do shell script "touch \"" & POSIX path of theItem & "\"" --do this to track the progress of the script based on folder modification date
                my processFiles(theItem) --operate recursively until all files are processed
            end if
        end if
    end repeat
end processFiles

Sikuli 文字的本质是:

switchApp("QuickTime Player 7")
keyDown(Key.CMD)
type("j")
keyUp(Key.CMD)
click([Author annotation tag])
click([Artist option])
keyDown(Key.CMD)
type("s")
keyUp(Key.CMD)
keyDown(Key.CMD)
type("w")
keyUp(Key.CMD)
keyDown(Key.CMD)
type("w")
keyUp(Key.CMD)
waitVanish([a QuickTime window])

我不是经验丰富的 Sikuli 开发人员,但几乎可以肯定,按键操作应该作为 UI 操作放入 AppleScript 中。这部分并不难。难的是单击选项。AppleScript 还可以检查 Author 属性;这些内容记录在 AppleScript 字典中,但该属性是只读的。

相关内容