现在更新博客的速度大大降低了,主要还是认为把自己做的题目传上来对别人和自己的帮助都不是很大。行,废话少说,我们切入正题吧。

刚刚闲来无事,想到之前看番的时候,有些另外下载的字幕会和视频名字不匹配,给观看带来不必要的麻烦,所以动手写了一个比较粗糙的字幕文件批量重命名的脚本。

代码已经上传到Yuuki_Dach’s GitHub,后续还会慢慢添加别的脚本。

其实代码并不复杂,就是先确定文件路径,然后手动输入视频文件后缀名和集数,然后开始运行就行了,这里还是把代码也贴一下,方便大家吧

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#! /bin/bash

echo "Before the opration stars, please make sure you have been in the right folder!"
while true; do
read -p "Do you want to continue? y/n" yn
case ${yn} in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done

echo "What is the videos' extension name?"
read video_extension_name

echo "How many episodes does it have?"
read total_video_episode_num

echo "These files were renamed successfully:"
for target_episode in `seq -w 1 ${total_video_episode_num}`
do
target_video=(*[^0-9]${target_episode}[^0-9]*${video_extension_name})
target_video=${target_video%${video_extension_name}}
for target_srt in `find -regex ".*[^0-9]?${target_episode}[^0-9]?.*srt"`
do
echo ${target_srt}
rename "s/.*[^0-9]?${target_episode}[^0-9]?.*?\./${target_video}/" ${target_srt}
done
done