The issue when you download movies online, is that most of the time the file name is going to be complete trash , filled with useless info like the team that made the rip or the website from where the movie was downloaded.
This is very annoying when you sort by name and the website made the idiotic decision to put their name in front of the actual film name.
for example here a typical movie name
[ Torrent9.info ] Dont.Think.Twice.2016.FRENCH.WEBRip.XviD-NEWCiNE.avi
the actual useful data that i wish to keep is Dont.Think.Twice.2016.avi
for this purpose i’ve developped a small bash script that will list all the files in a chosen directory then , if necessary , will rename the file.
xxxxxxxxxx
#the location of the folder full of movies to rename.
for file in /media/freebox/*
do
if [[ -f $file ]]; then
#that line will delete all the text after the date but keep the file extension.
nfile=$(echo $file | sed "s/\(20[0-1][0-8]\).*\(mkv\|avi\|mp4\)/\1.\2/")
#this line is going to try to delete a space a the start of the filename if it exist
nfile=$(echo $nfile | sed "s/\/ /\//")
#this line is going to delete double dots in the filename and replace them with simple dots
nfile=$(echo $nfile | sed -e "s/\.\./\./g")
#that line is going to delete everything between [] including the []
nfile=$(echo $nfile | sed -e 's/\[[^][]*\]//g')
#after all this work on the filename
#you can now check if the any changes have been made ,
if [[ "$file" == "$nfile" ]]
then
#if no change display this
echo "Not touched : $file"
else
#if change detected , rename the file
echo ______
echo Renamed :
echo "Original name : $file"
echo "Renamed to : $nfile"
echo ______
#doing the actual renaming
mv "$file" "$nfile"
fi
fi
done
this is not a very efficient script
but it’s fulfill it’s purpose and very rarely encounter a filename that he is unable to clean.