Skip to content

Instantly share code, notes, and snippets.

@thomaswitt
Created May 24, 2022 11:59
Show Gist options
  • Save thomaswitt/14f64ceea0142bb9a12e1b1a7fbfcb5c to your computer and use it in GitHub Desktop.
Save thomaswitt/14f64ceea0142bb9a12e1b1a7fbfcb5c to your computer and use it in GitHub Desktop.
Take an Instagram data export, use metadata from media.json file, rename pictures and add EXIF/IPTC date and title, so they're ready to import in a photo management application like iPhoto
#!/bin/bash
if [[ ! -s "media.json" ]]; then
echo "*** ERROR: No media.json file in current directory"
exit 1
fi
mkdir result
echo -n "Processing "
for row in $(cat media.json | jq -r '.[][] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
P_PATH=$(_jq '.path')
P_TAKEN_AT=$(_jq '.taken_at')
P_CAPTION=$(_jq '.caption')
P_FILENAME=$(date -u -j -f "%Y-%m-%dT%H:%M:%S+00:00" "${P_TAKEN_AT}" +"%Y-%m-%d-%H%M%S")
P_EXT=`echo "$P_PATH" | cut -d'.' -f2`
exiftool -q \
-AllDates="${P_TAKEN_AT}" \
-SpecialInstructions= \
-iptc:Caption-Abstract="${P_CAPTION}" \
-iptc:Keywords="Instagram" \
-iptc:ObjectName="${P_CAPTION}" \
-iptc:OriginatingProgram='Instagram' \
-iptc:codedcharacterset=utf8 \
-o "result/${P_FILENAME}.${P_EXT}" \
${P_PATH}
if [ $? -ne 0 ]; then
echo " - ERROR in result/${P_FILENAME}.${P_EXT} (from ${P_PATH})\n"
else
echo -n "."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment