[kwlug-disc] Regular Expression to Match Movie Titles and Year and Ignore the rest.
John Driezen
jdriezen at sympatico.ca
Sun Jan 5 05:01:15 EST 2025
I ended up modifying William's bash script to support multiple file name
arguments on the command line.
Here is the final program:
#
# Rename movie files
#
# Converts movie file names to a nice form expected by media servers
like Emby, Jellyfin, Plex.
# Usage: bash renamemoviefile.sh <file1> <file2> <file3>....
# Example Input: Zero.Dark.Thirty.2012.720p.BrRip.x264.BOKUTOX.YIFY.mp4
#
# Example Output: Zero Dark Thirty (2012)-720p.mp4
#
# Written by: William Park
#
# Modified by: John Driezen to accept multiple file name arguments.
#
# The mv command is commented out for safety. Run a trial FIRST!
for moviefile in "$@"
do
echo $moviefile | while IFS=. read -a x; do
y=
skip=0
for i in "${x[@]}"; do
case $i in
201[0-9]) y+=" ($i)" ;;
[0-9]*p) y+="-$i" ; skip=1 ;;
avi) y+=".$i" ;;
mkv) y+=".$i" ;;
mp4) y+=".$i" ;;
srt) y+=".$i" ;;
webp) y+=".$i" ;;
*) if [[ skip -eq 0 ]]; then y+="${y:+ }$i"; fi ;;
esac
done
echo "Renaming $moviefile as $y"
#mv $moviefile "$y"
done
done
Thank you to all for suggestions and comments.
John Driezen
jdriezen at symaptico.ca
More information about the kwlug-disc
mailing list