You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.4 KiB
49 lines
1.4 KiB
#!/bin/sh
|
|
|
|
error_log=.fix_gopro_filenames_error.log
|
|
|
|
if ! touch $error_log; then
|
|
printf '%b\n' "\e[1;31mERROR\e[1;37m:\e[0m Unable to write to current directory." >&2
|
|
exit 1
|
|
fi
|
|
printf '%s\n' 'Searching for GoPro video files...'
|
|
FILES=$(ls -1 | grep -E '^GX[0-9]{6}.MP4$')
|
|
if [ -z "$FILES" ]; then
|
|
printf '%b\n' "\e[1;31mERROR\e[1;37m:\e[0m No GoPro files with default names found in current directory." >&2
|
|
exit 1
|
|
fi
|
|
printf '%b\n' "\nFound:\n$FILES\n"
|
|
printf '%s' "Do you want to continue renaming these files? (y/N) "
|
|
read -n 1 response
|
|
if [ "$response" != "y" ] && [ "$response" != "Y" ]; then
|
|
printf '\n%s\n' "Aborted."
|
|
exit 1
|
|
fi
|
|
printf '\n%s\n' "Continuing..."
|
|
|
|
printf '%s\n' $FILES | while read -r i; do
|
|
sq=$(printf '%s\n' $i | awk '{print substr($0, 3, 2)}')
|
|
vn=$(printf '%s\n' $i | awk '{print substr($0, 5, 4)}')
|
|
oname="GX${sq}${vn}.MP4"
|
|
nname="GX${vn}_${sq}.MP4"
|
|
|
|
printf '%b' "Renaming \e[1;33m${oname}\e[0m to \e[1;32m${nname}\e[0m... "
|
|
if mv $oname $nname 2>>$error_log; then
|
|
printf '%b\n' "\e[1mDONE\e[0m"
|
|
else
|
|
printf '%b\n' "\e[1;31mFAIL\e[0m"
|
|
fi
|
|
done
|
|
|
|
if [ -s $error_log ]; then
|
|
printf '%b\n' " !!!\e[1;31m ERRORS ENCOUNTERED: \e[0m!!!\n------------" >&2
|
|
printf '%b\n' "$(cat $error_log)\n------------" >&2
|
|
rm "$error_log"
|
|
exit 3
|
|
else
|
|
printf '%b\n' "\e[1;34m Complete!\e[0m"
|
|
rm "$error_log"
|
|
exit 0
|
|
fi
|
|
|