A snippet of bash code i threw together to help myself. It doesnt do all the work, but it does most. It is not perfect, but it saved me hours of renaming, and the metadata came in after.
Look up the seasons on TheTVDB, put them all into their own temp folders.
Then you can run the script on the folder.
You tell the script the season, how far in to the file name ("_" as the split) to place the season (and episode offset if needed). It will then go through the folder adding in SXXEXX to the files.
It will replace spaces with _ so you dont have to worry.
So if you ran the script on a folder with:
[GROUP]_Anime_Name_123_[Numbers].mp4
[GROUP]_Anime_Name_124_[Numbers].mp4
[GROUP]_Anime_Name_125_[Numbers].mp4
[GROUP]_Anime_Name_126_[Numbers].mp4
with
aniname 11 3 4
It would change the files to
[GROUP]_Anime_Name_S11E04_123_[Numbers].mp4
[GROUP]_Anime_Name_S11E05_124_[Numbers].mp4
[GROUP]_Anime_Name_S11E06_125_[Numbers].mp4
[GROUP]_Anime_Name_S11E07_126_[Numbers].mp4
NOTE:
If there are double episodes, you will have to break there, do those separate, then run again with the offset.
If some files have a different number of "leading name chunks" before the drop point, you will have to do those separate as well
#!/bin/bash
#Input season like “01” or “11”
season=$1
#If a start point isnt provided, starts at episode 1
if [ $# -eq 3 ]
then
num=$3
else
num=1
fi
breakloc=$2
declare -i breakloc
declare -i num
#Replaces spaces with underscores in all files
for i in *
do
CleanFile=`echo $i | sed 's/ /_/g'`
diff <(echo "$i" ) <(echo "$CleanFile") >> /dev/null
if [ $? -ne 0 ] ; then
mv "$i" $CleanFile
fi
done
#Loops through all files folder script is executed from
for i in *
do
#Adds a trailing 0 to episode number if needed
wordnum=printf "%02d" $num
#Breaks episode name into an array based on "_" as the split
IFS='_'
read -ra ADDR <<< "$i"
IFS=' '
Counter=0
declare -i Counter
newname=""
#Adds the pieces before the number to the new file name
while [ $Counter -lt $breakloc ]
do
newname=${newname}${ADDR[$Counter]}_
let Counter=Counter+1
done
#Adds the Season and Episode Number
newname=${newname}S${season}E${wordnum}_
Counter=$breakloc
endname=${#ADDR[@]}
let endname=endname-1
#Adds the rest of the file name back in
while [ $Counter -lt $endname ]
do
newname=${newname}${ADDR[$Counter]}_
let Counter=Counter+1
done
#Adds the end of the file name without a trailing _
newname=${newname}${ADDR[$Counter]}
#Renames file
mv "$i" $newname
#Increments episode number for next file
num=$num+1
done