Last active
March 28, 2019 03:32
-
-
Save terrancewong/e6fd0a67558c17b39ea2d0a765744924 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
# MoveImagesByDate - Digital Image/Motion Picturefile managing script for Civilized OSes | |
# Copyright (C) 2009-2019 Terance | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# requires Phil Harvey's exiftool (almost any version) | |
# requires exiv2 http://exiv2.org | |
# | |
# Version v.0.1, 20090801 | |
# 0.2, 20161027, faster | |
# 0.8, 20190328, switch to exiv2 for better performance | |
# | |
# with Thanks to Aquamacs | |
# | |
# set -e | |
datecode=$(date "+%Y%m%d.%H%M%S") | |
listFile=$(mktemp) | |
doFile=do.${datecode}.sh | |
UndoFile=undo.${datecode}.sh | |
which xargs > /dev/null || echo "Please install xargs first" | |
which exiv2 > /dev/null || echo "Please install exiv2 first" | |
echo "gathering date info..." | |
# no videos supported by exiv2 | |
find . -maxdepth 1 -type f -iname "*.nef" -o -iname "*.jpg" -o -iname "*.tif" -o -iname "*.dng" -o -iname "*.png" -o -iname "*.heic" -o -iname "*.cr2" \ | |
| xargs -r exiv2 -p t -K "Exif.Image.DateTimeOriginal" $* \ | |
| gawk '{ printf ("mv -n %s %s\n", $1, $5)} ' | tr -d ':' \ | |
> ${listFile} | |
# video..., slow while not messing with tricky multiple file output format of exiftool | |
if [ -f "*.MOV" ] ; then | |
for A in *.MOV ; do | |
D=$(exiftool -fast -s -s -s -d %Y%m%d -CreateDate $A) | |
echo $D | |
if [ -n $D ] ; then | |
echo "mv -n $A $D" >> ${listFile} | |
fi | |
done | |
fi | |
# mkdir of each date | |
awk '{print $4 }' ${listFile} | sort | uniq | xargs -r echo mkdir -p > ${doFile} | |
cat ${listFile} >> ${doFile} | |
# generate undo script | |
awk '{printf("mv -p %s/%s ./ \n", $4, $3); }' ${listFile} > ${UndoFile} | |
awk '{print $4 }' ${listFile} | sort | uniq | xargs echo rmdir -p >> ${UndoFile} | |
echo "moving files..." | |
. ${doFile} | |
rm -f ${listFile} | |
chmod 755 ${UndoFile} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment