我如何告诉这个 Applescript 跳过一些文件? [英] How to I tell this Applescript to skip some files?

查看:20
本文介绍了我如何告诉这个 Applescript 跳过一些文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我,使用 Applescript 使用 Handbrake CLI 将一大堆 mv4 文件 bash 转换为 640x480.我有一个 Applescript,我发现某处更改了我的参数,并且效果很好.但为了节省时间,我希望脚本跳过已经是 640x480 的文件,因为并非所有文件都需要转换.我该怎么做?

Im, using an Applescript to bashconvert a whole bunch of mv4 files to 640x480 using Handbrake CLI. I have a applescript I found somewhere changed to my parameters, and it works great. But to save time, I want the script to skip files that are already 640x480, since not all files need conversion. How would I go about that?

脚本如下:

--on adding folder items to this_folder after receiving these_items
with timeout of (720 * 60) seconds
tell application "Finder"
    --Get all m4v files that have no label color yet, meaning it hasn’t been processed
    set allFiles to every file of entire contents of ("FIRSTHD:Users:jerry:Desktop:Omkodning" as alias) whose ((name extension is "m4v") and label index is 0)
    --Repeat for all files in above folder
    repeat with i from 1 to number of items in allFiles
        set currentFile to (item i of allFiles)
        try
            --Set to gray label to indicate processing
            set label index of currentFile to 7
            --Assemble original and new file paths
            set origFilepath to quoted form of POSIX path of (currentFile as alias)
            set newFilepath to (characters 1 thru -5 of origFilepath as string) & "mp4'"
            --Start the conversion
            set shellCommand to "nice /Applications/HandBrakeCLI -i " & origFilepath & " -o " & newFilepath & " -e ffmpeg4 -b 1200 -a 1 -E faac -B 160 -R 29.97 -f mp4 –crop 0:0:0:0 crf 24 -w 640 -l 480  ;"
            do shell script shellCommand
            --Set the label to green in case file deletion fails
            set label index of currentFile to 6
            --Remove the old file
            set shellCommand to "rm -f " & origFilepath
            do shell script shellCommand
        on error errmsg
            --Set the label to red to indicate failure
            set label index of currentFile to 2
        end try
    end repeat
end tell
end timeout
--end adding folder items to

推荐答案

为清晰起见进行了编辑....

由于 HandBreakCLI 没有任何选项告诉它在分辨率为 640x480 时不进行转换,因此您必须在脚本中处理这些逻辑.很容易做到.

Since HandBreakCLI doesn't have any options to tell it not to convert if the resolution is 640x480, you have to handle that bit of logic in your script. It is easily done.

所以你的脚本需要做的就是......

So all your script needs to do is...

get the video file resolution

If file is not at desired resolution then
    convert the file
else
    skip it
end if

因此,正如 此处讨论的那样,您可以使用免费提供的mediainfo 命令行工具来获取视频分辨率.

So, as discussed here, you can use the freely available mediainfo command line tool to get the video resolution.

这里有一些 Applescript 代码,您可以复制/粘贴并运行它们以查看它是如何工作的...

Here is some applescript code which you can copy/paste and run to see how it works...

set filterStr to " | grep pixels | tr -d [:alpha:][:blank:][:punct:]"

set allFiles to (choose file with multiple selections allowed)

repeat with i from 1 to number of items in allFiles
    set currentFile to (item i of allFiles)

    set cmdStr to "/usr/local/bin/mediainfo " & ¬
        quoted form of POSIX path of currentFile & filterStr

    set h to 0
    set w to 0
    try
        set fileInfo to do shell script (cmdStr)
        set {w, h} to every paragraph of fileInfo
    end try

    if w is not 640 and h is not 480 then
        log w & " x " & h

        # Convert to desired resolution....
    end if
end repeat

希望有所帮助.

这篇关于我如何告诉这个 Applescript 跳过一些文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆