Skip to content

Instantly share code, notes, and snippets.

@dmacsuibhne
Last active December 13, 2023 17:23
Show Gist options
  • Save dmacsuibhne/e2b9e2f2f9443145f5519a1dd3fd9730 to your computer and use it in GitHub Desktop.
Save dmacsuibhne/e2b9e2f2f9443145f5519a1dd3fd9730 to your computer and use it in GitHub Desktop.
Restore video creation date after it has been stripped by e.g. Google-Photos or ffmpeg
#!/bin/bash
set -o nounset
directory_original=./keep/conv35veryslow
for filepath in ${directory_original}/*; do
# echo $filepath
if (echo $filepath | grep -P 'VID_20\d{6}_\d{6}[^\d]' > /dev/null); then
# echo "FORMAT1 VID_YYYYMMDD_hhmmss"
partial_filename=$(echo -n $filepath | sed 's#.*VID_##g')
YYYY="${partial_filename:0:4}"
MM="${partial_filename:4:2}"
DD="${partial_filename:6:2}"
hh="${partial_filename:9:2}"
mm="${partial_filename:11:2}"
ss="${partial_filename:13:2}"
# echo date is $YYYY-$MM-$DD $hh-$mm-$ss
elif (echo $filepath | grep -P 'VID_20\d{6}_\d{9}[^\d]' > /dev/null); then
# echo "FORMAT2 VID_YYYYMMDD_hhmmss???"
partial_filename=$(echo -n $filepath | sed 's#.*VID_##g')
YYYY="${partial_filename:0:4}"
MM="${partial_filename:4:2}"
DD="${partial_filename:6:2}"
hh="${partial_filename:9:2}"
mm="${partial_filename:11:2}"
ss="${partial_filename:13:2}"
# echo date is $YYYY-$MM-$DD $hh-$mm-$ss
elif (echo $filepath | grep -P 'VID20\d{12}[^\d]' > /dev/null); then
# echo "FORMAT3 VIDYYYYMMDDhhmmss"
partial_filename=$(echo -n $filepath | sed 's#.*VID##g')
YYYY="${partial_filename:0:4}"
MM="${partial_filename:4:2}"
DD="${partial_filename:6:2}"
hh="${partial_filename:8:2}"
mm="${partial_filename:10:2}"
ss="${partial_filename:12:2}"
# echo date is $YYYY-$MM-$DD $hh-$mm-$ss
elif (echo $filepath | grep -P 'Record_\d{4}-\d{2}-\d{2}-\d{2}-\d{2}-\d{2}[^\d]' > /dev/null); then
# echo "FORMAT4 Record_YYYY-MM-DD-hh-mm-ss"
partial_filename=$(echo -n $filepath | sed 's#.*/Record_##g')
YYYY="${partial_filename:0:4}"
MM="${partial_filename:5:2}"
DD="${partial_filename:8:2}"
hh="${partial_filename:11:2}"
mm="${partial_filename:14:2}"
ss="${partial_filename:17:2}"
# echo date is $YYYY-$MM-$DD $hh-$mm-$ss
else
echo "ERROR: NO FORMAT DETECTED: $filepath"
exit 1
fi
(set -x && TZ=UTC touch -a -m -t "$YYYY$MM$DD$hh$mm.$ss" $filepath)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment