1
0
Fork 0
mirror of https://github.com/SinTan1729/random.git synced 2024-12-27 05:28:37 -06:00
random/rename-subs

23 lines
980 B
Text
Raw Normal View History

2022-03-06 14:14:22 -06:00
#!/bin/sh
# It renames the .srt files in a directory to match the .mp4 movie names (since those are the formats I usually need).
2022-05-26 20:39:51 -05:00
# If the subtitles are in a subfolder, the script should still work as long as there's only one .srt file.
2022-03-06 14:14:22 -06:00
# It makes the subs discoverable by virtually any video player.
# Optionally takes a language arguments e.g. en to rename to .en.srt
2022-03-06 14:14:22 -06:00
2023-05-22 20:45:18 -05:00
for f in *.mp4 *.mkv; do
2022-03-06 14:14:22 -06:00
if [ -f "$f" ]; then
h=$(basename "$f" .mp4)
echo "Renaming the subtitle (if any) accompanying $h.mp4..."
2022-05-26 20:39:51 -05:00
n=$(find . -maxdepth 2 -name "*.srt" -printf '.' | wc -m)
2023-02-28 23:24:31 -06:00
if [ $n -eq 1 ] && ! [ -f "$h.srt" ]; then
# Check if language was given
[ -z $1 ] && ext="srt" || ext="$1.srt"
find . -maxdepth 2 -name "*.srt" -exec mv "{}" "$h.$ext" \;
2022-03-06 14:14:22 -06:00
echo "Done!"
else
2023-02-28 23:24:31 -06:00
echo "Unable to find unique srt file that needs to be renamed. It might already have the proper name."
2022-03-06 14:14:22 -06:00
fi
fi
2023-02-28 23:24:31 -06:00
done