Created
November 12, 2020 03:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "$@"' _ {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is a much better method which utilize those json files to get exif data.