更新时间:2023-02-22 17:34:01
使用 shell 脚本会更容易,但可以尝试以下操作:
It would be easier to use a shell script, but try something like this:
on hazelProcessFile(theFile)
set text item delimiters to ":"
set filename to last text item of (theFile as text)
set text item delimiters to "."
if filename contains "." then
set base to text items 1 thru -2 of filename as text
set extension to "." & text item -1 of filename
else
set base to filename
set extension to ""
end if
set text item delimiters to {"720p", "HDTV", "x264", "IMMERSE", "-", "E01", "..."}
set ti to text items of base
set text item delimiters to ""
set newbase to ti as text
set newbase to replace(newbase, "S0", "Season ")
set newbase to replace(newbase, ".", " ") & extension
tell application "Finder"
if newbase contains "Season" then
move theFile to POSIX file "/Volumes/LaCie/Midia/Series/"
set name of result to newbase
else
move theFile to POSIX file "/Volumes/LaCie/Midia/Filmes/"
end if
end tell
end hazelProcessFile
on replace(input, x, y)
set text item delimiters to x
set ti to text items of input
set text item delimiters to y
ti as text
end replace
POSIX 文件
这是一个shell脚本版本:
here is a shell script version:
basename=${1##*/}
base=${basename%.*}
[[ $basename = *.* ]] && ext=".${basename##*.}" || ext=
for x in 720p HDTV x264 IMMERSE - E01 ...; do base=${base//"$x"}; done
base=${base//S0/Season}
base=${base//./ }
if [[ $base = *Season* ]]; then
mv "$1" "/Volumes/LaCie/Midia/Series/$base$ext"
else
mv "$1" /Volumes/LaCie/Midia/Movies/
fi
编辑 2:例如,这会将 here.comes.honey.boo.boo.s01e04.720p-killers.mkv
移动到名为 Here Comes Honey Boo Boo Season 1代码>:
Edit 2: this would for example move here.comes.honey.boo.boo.s01e04.720p-killers.mkv
to a folder named Here Comes Honey Boo Boo Season 1
:
d=${1##*/}
if [[ $d =~ [Ss][0-9][0-9][Ee][0-9][0-9] ]]; then
d=$(sed -E 's/[ .][Ss]([0-9][0-9])[Ee][0-9][0-9].*/ Season \1/;s/ Season 0/ Season /;s/\./ /g' <<< "$d")
d=$(ruby -r rubygems -e 'require "titlecase"; puts ARGV[0].titlecase' "$d")
target="/Volumes/LaCie/Midia/Series/$d"
mkdir -p "$target"
mv "$1" "$target"
else
mv "$1" "/Volumes/LaCie/Midia/Movies"
fi
titlecase gem 可以通过 sudo gem install titlecase
安装.
The titlecase gem can be installed with sudo gem install titlecase
.