Skip to content

Instantly share code, notes, and snippets.

@ileathan
Last active October 27, 2023 03:28
Show Gist options
  • Save ileathan/04aa9a2b06f4edbeed04e54c380340d4 to your computer and use it in GitHub Desktop.
Save ileathan/04aa9a2b06f4edbeed04e54c380340d4 to your computer and use it in GitHub Desktop.
Same as my last gist but probably what more people want. Renames custom pictures correctly.
# Just move the images.
# Usage: bash rename2.sh "playlistfile.lpl" "/retroarch/thumbnails/folder"
IFS=$'\n'
for file in $(cat "$1" | grep -oP '.*"path":.*/\K.*\.([^"]*)'); do
ext=${file##*.}
escfile=$(echo $file | perl -pe 's/([[\]()+\$^{}])/\\$1/g')
newname=$(cat "$1" | grep -zoP "(/|\\\)$escfile"'",\s*\"label\": \"\K[^"]*')
newname=$(echo "$newname" | perl -pe 's/[&*\/:`<>?\|]/_/g')
dir="${1:0:-4}"
if [[ "${file:0:-((${#ext}+1))}" != "$newname" ]]; then
if [ -f "$2/$dir/Named_Snaps/$newname.png" ]; then
echo "Good."
else
mv -v "$2/$dir/Named_Boxarts/${file:0:-((${#ext}+1))}.png" "$2/$dir/Named_Boxarts/$newname.png"
mv -v "$2/$dir/Named_Titles/${file:0:-((${#ext}+1))}.png" "$2/$dir/Named_Titles/$newname.png"
mv -v "$2/$dir/Named_Snaps/${file:0:-((${#ext}+1))}.png" "$2/$dir/Named_Snaps/$newname.png"
fi
fi
done
unset IFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment