1
0
Fork 0
mirror of https://github.com/SinTan1729/random.git synced 2024-12-26 05:08:36 -06:00
random/rename-subs

20 lines
811 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.
for f in *.mp4; do
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
find . -maxdepth 2 -name "*.srt" -exec mv "{}" "$h.srt" \;
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