mirror of
https://github.com/sbrl/bin.git
synced 2018-01-10 21:33:46 +00:00
Enhance jpeg date detection
This commit is contained in:
parent
0054087ac1
commit
07938643c9
1 changed files with 38 additions and 2 deletions
|
@ -4,6 +4,9 @@
|
||||||
# organises them into a folder structure based on the month and year
|
# organises them into a folder structure based on the month and year
|
||||||
# they were last modified (taken).
|
# they were last modified (taken).
|
||||||
|
|
||||||
|
# Sources and References
|
||||||
|
# - Bash controlled paralellisation - http://unix.stackexchange.com/a/216475/64687
|
||||||
|
|
||||||
DRY_RUN=false
|
DRY_RUN=false
|
||||||
|
|
||||||
while test $# -gt 0
|
while test $# -gt 0
|
||||||
|
@ -28,13 +31,36 @@ do
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
find . -maxdepth 1 \( -iname "*.jpg" -o -iname "*.mp4" \) -print0 | while read -r -d '' filename
|
Months=(Zero January February March April May June July August September October November December);
|
||||||
do
|
|
||||||
|
handle_file() {
|
||||||
|
local filename=$1;
|
||||||
|
|
||||||
echo -ne "Processing ${filename} - ";
|
echo -ne "Processing ${filename} - ";
|
||||||
|
|
||||||
|
rawFilename=$(basename "${filename}");
|
||||||
|
extension=${filename##*.};
|
||||||
|
extension=${extension,,};
|
||||||
|
|
||||||
takenYear=$(date -r "${filename}" +%Y);
|
takenYear=$(date -r "${filename}" +%Y);
|
||||||
takenMonth=$(date -r "${filename}" +%-m);
|
takenMonth=$(date -r "${filename}" +%-m);
|
||||||
takenMonthText=$(date -r "${filename}" +%B);
|
takenMonthText=$(date -r "${filename}" +%B);
|
||||||
|
|
||||||
|
# Extract the date taken from jpegs
|
||||||
|
if [[ "${extension}" == "jpg" ]] || [[ "${extension}" == "jpeg" ]];
|
||||||
|
then
|
||||||
|
takenDate=$(jhead "${filename}" | grep -i 'Date/Time' | cut -d' ' -f6-7);
|
||||||
|
takenChars=$(echo ${takenDate} | wc -c);
|
||||||
|
if [[ ${takenChars} -gt 1 ]];
|
||||||
|
then
|
||||||
|
takenYear=$(echo ${takenDate} | cut -d ':' -f1);
|
||||||
|
takenMonth=$(echo ${takenDate} | cut -d ':' -f2);
|
||||||
|
takenMonthUnpadded=$(echo ${takenMonth//0});
|
||||||
|
takenMonthText=${Months[$takenMonthUnpadded]};
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
newFolder="${takenYear}/${takenMonth}-${takenMonthText}/";
|
newFolder="${takenYear}/${takenMonth}-${takenMonthText}/";
|
||||||
newFilename="${newFolder}${filename}";
|
newFilename="${newFolder}${filename}";
|
||||||
|
|
||||||
|
@ -49,8 +75,18 @@ do
|
||||||
mv "${filename}" "${newFilename}";
|
mv "${filename}" "${newFilename}";
|
||||||
|
|
||||||
echo Done\!;
|
echo Done\!;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set the number of paralell jobs to the number of cpus
|
||||||
|
N=$(grep -c ^processor /proc/cpuinfo);
|
||||||
|
|
||||||
|
find . -maxdepth 1 \( -iname "*.jpg" -o -iname "*.mp4" -o -iname "*.avi" -o -iname "*.png" \) -print0 | while read -r -d '' filename
|
||||||
|
do
|
||||||
|
((i=i%N)); ((i++==0)) && wait;
|
||||||
|
handle_file "${filename}"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "*** Complete! ***"
|
echo "*** Complete! ***"
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue