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.
|
2023-05-21 22:03:10 -05:00
|
|
|
# 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
|
2023-11-11 03:16:00 -06:00
|
|
|
h="${f%.*}"
|
2022-03-06 14:14:22 -06:00
|
|
|
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
|
2023-05-21 22:03:10 -05:00
|
|
|
# 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
|