Created
December 8, 2020 03:52
-
-
Save chaomai/ddfa6e923e44f0d92b4145f766c550b9 to your computer and use it in GitHub Desktop.
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 | |
dir=$1 | |
function process() { | |
local final_dir="/Users/chaomai/Downloads/final_imgs" | |
local dest_dir="/Users/chaomai/Downloads/dest_imgs" | |
local f=$1 | |
echo $f | |
local file_name=$(basename "$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 | |
local dest_dir_dt=${dest_dir}/${dir_t} | |
if [[ ! -d "$dest_dir_dt" ]]; then | |
mkdir -p "$dest_dir_dt" | |
fi | |
if [[ -e "$dest_dir_dt"/"$file_name" ]]; then | |
echo "warn $dest_dir_dt exists" >> /dev/stderr | |
fi | |
echo "no image time for $f" | |
mv "$f" "$dest_dir_dt" | |
else | |
local final_dir_dt=${final_dir}/${dir_t} | |
if [[ ! -d "$final_dir_dt" ]]; then | |
mkdir -p "$final_dir_dt" | |
fi | |
if [[ -e "$final_dir_dt"/"$file_name" ]]; then | |
echo "warn $final_dir_dt exists" >> /dev/stderr | |
else | |
mv "$f" "$final_dir_dt" | |
fi | |
fi | |
fi | |
} | |
export -f process | |
find "$dir" -type f -name '*' ! -name 'metadata.json' -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