Skip to content

Instantly share code, notes, and snippets.

@jooray
Created August 12, 2024 08:14
Signal media comes without metadata (which is good). But for importing into photo apps, it makes sense to have at least date and time, which is in the filename anyway.
#!/bin/bash
for file in signal-*.jpeg signal-*.mp4; do
filename=$(basename "$file")
date_time=$(echo "$filename" | cut -d '-' -f 2-5 | sed 's/_/ /g' | sed 's/-/ /g' | awk '{print $1 "-" $2 "-" $3 " " $4}' | sed 's/ /:/4')
# Add metadata to images and videos
if [[ $file == *.jpeg ]]; then
exiftool -overwrite_original -DateTimeOriginal="$date_time" -DateTimeDigitized="$date_time" -DateTime="$date_time" "$file"
elif [[ $file == *.mp4 ]]; then
exiftool -overwrite_original -MediaModifyDate="$date_time" -MediaCreateDate="$date_time" -TrackModifyDate="$date_time" -TrackCreateDate="$date_time" "$file"
fi
# Convert date_time to touch format
touch_date_time=$(date -j -f "%Y-%m-%d %H%M%S" "$date_time" "+%Y%m%d%H%M.%S")
# Change the modified time of the file
touch -t "$touch_date_time" "$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment