Skip to content

Instantly share code, notes, and snippets.

@ileathan
Last active October 27, 2023 03:28
Show Gist options
  • Save ileathan/f48cbfaeec9eb77faff12c90299641a3 to your computer and use it in GitHub Desktop.
Save ileathan/f48cbfaeec9eb77faff12c90299641a3 to your computer and use it in GitHub Desktop.
#
# Renames all retroarch thumbnails names, roms names, and reupdates the playlist.lpl files with said information.
#
# If your playlists names match your rom directories this will rename all cusom images and roms according to the lpl
# file passed in. Copy all your playlists over to where this script is located and from a wsl (windows subsystem for linus) console
# and ussage would be:
#
# bash rename.sh "PlaylistFile.lpl" "/your/retroarch/thumbnails/folder" "/your/retroarch/roms/folder" "/your/retroarch/playlists/folder"
#
# To update your entire retroarch at once you can follow the above advice and run:
#
# for f in *.lpl;do bash rename.sh "PlaylistFile.lpl" "/your/retroarch/thumbnails/folder" "/your/retroarch/roms/folder" "/your/retroarch/playlists/folder" 2>/dev/null;done
#
IFS=$'\n'
for file in $(cat "$1" | grep -oP '.*/\K.*\.([^"]*)'); do
ext=${file##*.}; pngname=${file:0:-((${#ext}+1))}
escfile=$(echo $file | perl -pe 's/([[\]()+\$^{}])/\\$1/g')
newname=$(cat "$1" | grep -zoP "$escfile"'",\s*\"label\": \"\K[^"]*')
newname=$(echo "$newname" | perl -pe 's/[&*\/:`<>?\|]/_/g')
if [[ "$pngname" != "$newname" ]]; then
dir="${1:0:-4}"
mv "/$2/$dir/Named_Titles/$pngname.png" "/$2/$dir/Named_Titles/$newname.png"
mv "/$2/$dir/Named_Snaps/$pngname.png" "/$2/$dir/Named_Snaps/$newname.png"
mv "/$2/$dir/Named_Boxarts/$pngname.png" "/$2/$dir/Named_Boxarts/$newname.png"
mv "/$3/$dir/$file" "/$3/$dir/$newname.$ext"
perl -i -pe "s/$escfile\"/$newname.$ext\"/g" "/$4/$1"
fi
done
unset IFS
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment