Skip to content

Instantly share code, notes, and snippets.

@miraclx
Created November 11, 2020 21:48
Show Gist options
  • Select an option

  • Save miraclx/ebe4dc9e7d21f1224b78c389ffecf90f to your computer and use it in GitHub Desktop.

Select an option

Save miraclx/ebe4dc9e7d21f1224b78c389ffecf90f to your computer and use it in GitHub Desktop.
Correct ctime on WhatsApp media artifacts
Correct timestamps on WhatsApp media artifacts
# How it works
WhatsApp saves its media files in the format `{TYPE}-{YYYY}{MM}{DD}-WA{NNNN}.{EXT}`
## Examples
- Image: `IMG-20190806-WA0026.jpg`
- Sticker: `STK-20191126-WA0010.webp`
- Audio: `AUD-20181227-WA0045.opus`
- Animated Gifs: `VID-20190103-WA0003.mp4`
- Voice Notes: `PTT-20200303-WA0018.opus`
So, this script extracts the `{YYYY}{MM}{DD}` part of the filename and modifies the filesystem creation time.
# Requirements
- exiv2 (optional, images only)
# How to run
Please run this within the media folders you want this to work in
i.e
$ cd "WhatsApp/Media/WhatsApp Images"
$ # <run here>
# Command
$ find . -type f -name '*' ! -name .nomedia -exec sh -c '
ofile=$1
dir=${ofile%/*}
file=$(basename $ofile)
year=${file:4:4}
month=${file:8:2}
day=${file:10:2}
echo "[$ofile]: {year=$year}{month=$month}{day=$day}"
# exiv2 -M"set Exif.Image.DateTime $year:$month:$day" "$file"
touch -t "$year$month$day""1500" "$ofile"
' sh {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment