它可以实现它的目标,但我非常确定有一个更有效/更聪明的解决方案:
#!/bin/bash
find . -iname "*.mp4" | while read f
do
id=$(echo $f | sed -n 's/.*.S\([0-9]\+\)E\([0-9]\+\)..*/\1x\2/p' | sed 's/^0*//')
if [ -z "$id" ]; then
echo "Warning! there's no match for $f"
else
srt=(*$id*)
newName=$(echo $srt | sed 's/ (English).srt/.mp4/g')
mv "$f" "$newName"
fi
done
第一部分采用srt文件的名称并重命名mp4文件。
for i in *" (Español (España)).srt"
do
iconv -f=ISO8859-1 -t=UTF-8 "$i" > "${i%%" (Español (España)).srt"}.esp.srt"
done
sleep 0.5
for i in *".srt"
do
rm *" (Español (España)).srt"
done
以上代码,更改srt文件的编码
for i in *".mp4"
do
i=${i%.mp4}
mkvmerge -o "$i.mkv" \
"--language" "1:eng" \
"-a" "1" "-d" "0" "-S" "-T" "$i.mp4" \
"--language" "0:eng" \
"-s" "0" "-D" "-A" "-T" "$i (English).srt" \
"--language" "0:spa" \
"-s" "0" "-D" "-A" "-T" "$i.esp.srt" \
"--track-order" "0:0,0:1,1:0,2:0"
done
find . -type f ! -name "*.mkv" ! -name "*.sh" -delete
for files in *.mkv
do
mv "$files" "${files%.mkv}.mp4"
done
notify-send -t 2000 "Fin de la conversión"
后一部分,将mp4文件与srt文件合并。
答案 0 :(得分:0)
我没有做太多改变。主要的是我整理了mkvmerge
电话 - 太多的报价看起来非常混乱:
#!/bin/bash
find . -iname "*.mp4" |
while IFS= read -r f; do
id=$(sed -n 's/.*.S\([0-9]\+\)E\([0-9]\+\)..*/\1x\2/p' <<< "$f" | sed 's/^0\+//')
if [ -z "$id" ]; then
echo "Warning! there's no match for $f"
else
for srt in *"$id"*; do
newName=$(sed 's/ (English).srt/.mp4/g' <<< "$srt")
mv "$f" "$newName"
done
fi
done
for i in *" (Español (España)).srt"; do
iconv -f=ISO8859-1 -t=UTF-8 "$i" > "${i%%" (Español (España)).srt"}.esp.srt" &&
rm "$i"
done
#sleep 0.5
for i in *".mp4"; do
i=${i%.mp4}
mkvmerge -o "$i.mkv" \
--language 1:eng -a 1 -d 0 -S -T "$i.mp4" \
--language 0:eng -s 0 -D -A -T "$i (English).srt" \
--language 0:spa -s 0 -D -A -T "$i.esp.srt" \
--track-order 0:0,0:1,1:0,2:0
done
find . -type f ! -name "*.mkv" ! -name "*.sh" -delete
for f in *.mkv; do
mv "$f" "${f%.mkv}.mp4"
done
notify-send -t 2000 "Fin de la conversión"