Skip to content

Instantly share code, notes, and snippets.

@chaomai
Created November 12, 2020 03:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaomai/b2054ee9895d5580e745d0da6d358ad5 to your computer and use it in GitHub Desktop.
Save chaomai/b2054ee9895d5580e745d0da6d358ad5 to your computer and use it in GitHub Desktop.
check google takeout images, set a time for those without timestamp, and move them to destination directory
#!/usr/bin/env bash
function set_ts() {
local f=$1
dto=$($GNUBIN_COREUTILS/date -d "$dir_t" "+%Y:%m:%d 00:00:00")
echo exiftool -datetimeoriginal="$dto" "$f"
exiftool -datetimeoriginal="$dto" "$f"
local dest_path=$dest_dir/$dir_d
if [[ ! -d "$dest_path" ]]; then
echo mkdir "$dest_path"
mkdir "$dest_path"
fi
echo mv "$f" "$dest_path"
mv "$f" "$dest_path"
}
function process() {
local dest_dir="/Users/chaomai/Downloads/final_imgs"
local f=$1
echo $f
local dir_name=$(dirname "$f")
local dir_d=$(basename "$dir_name")
local dir_t=$(echo "$dir_d" | egrep -o '[0-9]{4}-[0-9]{2}-[0-9]{2}')
if [[ ! -z "$dir_t" ]]; then
local d=$(exiftool -DateTimeOriginal "$f")
if [[ -z "$d" ]]; then
echo "no image time for $f"
set_ts "$f" "$dir_t"
else
local dest_path=$dest_dir/$dir_d
if [[ ! -d "$dest_path" ]]; then
echo mkdir "$dest_path"
mkdir "$dest_path"
fi
echo mv "$f" "$dest_path"
mv "$f" "$dest_path"
fi
echo ""
fi
}
find ./takeout_imgs -type f -name '*.json' -delete
find ./takeout_imgs -type f -name '*.html' -delete
export -f process
export -f set_ts
find ./takeout_imgs -type f -name '*.mp4' -print0 | xargs -0 -n 1 -P 1 -I {} bash -c 'process "$@"' _ {}
@chaomai
Copy link
Author

chaomai commented Nov 29, 2020

There is a much better method which utilize those json files to get exif data.

exiftool -r -d %s -tagsfromfile "%d/%F.json" "-GPSAltitude<GeoDataAltitude" "-GPSLatitude<GeoDataLatitude" "-GPSLatitudeRef<GeoDataLatitude" "-GPSLongitude<GeoDataLongitude" "-GPSLongitudeRef<GeoDataLongitude" "-Keywords<Tags" "-Subject<Tags" "-Caption-Abstract<Description" "-ImageDescription<Description" "-DateTimeOriginal<PhotoTakenTimeTimestamp" -ext "*" -overwrite_original -progress --ext json FileOrDir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment