Commit b4623fe7 authored by Dmitri Popov's avatar Dmitri Popov

Fix geotagging, add getopt

parent 2eca18b5
......@@ -4,11 +4,15 @@
# License: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
# Source code: https://gitlab.com/dmpop/momo
# opkg install bc jq curl rsync perl-image-exiftool
# opkg install getopt bc jq curl perl-image-exiftool
# Photo and RAW file extensions
EXT="JPG"
RAW="ARW"
# Check whether the required packages are installed
if [ ! -x "$(command -v bc)" ] || [ ! -x "$(command -v jq)" ] || [ ! -x "$(command -v curl)" ] || [ ! -x "$(command -v exiftool)" ]; then
echo "Make sure that the following tools are installed on your system: bc, jq, curl, exiftool"
if [ ! -x "$(command -v getopt)" ] || [ ! -x "$(command -v bc)" ] || [ ! -x "$(command -v jq)" ] || [ ! -x "$(command -v curl)" ] || [ ! -x "$(command -v exiftool)" ]; then
echo "Make sure that the following tools are installed on your system: getopt, bc, jq, curl, exiftool"
exit 1
fi
......@@ -97,7 +101,7 @@ echo "Transferring files..."
echo "---------------------"
echo
results=$(find "$src" -type f -iname "*.JPG" -o -iname "*.ARW")
results=$(find "$src" -type f -iname "*.$EXT" -o -iname "*.$RAW")
lines=$(echo -e "$results" | wc -l)
for line in $(seq 1 $lines)
do
......@@ -105,6 +109,7 @@ for line in $(seq 1 $lines)
echo "$file"
cp "$file" "$target"
done
cd "$target"
if [ ! -z "$location" ]; then
......@@ -124,18 +129,20 @@ if [ ! -z "$location" ]; then
fi
fi
if [ ! -z "$location" ]; then
echo
echo "--------------"
echo "Geotagging ..."
echo "--------------"
echo
results=$(find "$target" -type f -iname "*.JPG")
results=$(find "$target" -type f -iname "*.$EXT")
lines=$(echo -e "$results" | wc -l)
for line in $(seq 1 $lines)
do
file=$(echo -e "$results" | sed -n "$line p")
exiftool -overwrite_original -GPSLatitude=$lat -GPSLatitudeRef=$latref -GPSLongitude=$lon -GPSLongitudeRef=$lonref "$file"
done
done
fi
# Check whether the Dark Sky API is reachable
check2=$(wget -q --spider https://api.darksky.net/)
......@@ -146,6 +153,7 @@ check2=$(wget -q --spider https://api.darksky.net/)
echo "-------------------------"
echo
# Obtain and write copyright camera model, lens, and weather conditions
results=$(find "$target" -type f -iname "*.$EXT")
for line in $(seq 1 $lines)
do
file=$(echo -e "$results" | sed -n "$line p")
......@@ -154,7 +162,7 @@ check2=$(wget -q --spider https://api.darksky.net/)
t=$(exiftool -d %Y-%m-%d -DateTimeOriginal "$file" | cut -d":" -f2 | tr -d " " | xargs -I dt date --date=dt +"%s")
camera=$(exiftool -Model "$file" | cut -d":" -f2 | tr -d " ")
lens=$(exiftool -LensID "$file" | cut -d":" -f2)
curl -k "https://api.darksky.net/forecast/"$api_key"/"$lat","$lon","$t"?units=si&exclude=currently,hourly,flags" > "$json"
curl -k "https://api.darksky.net/forecast/$api_key/$lat,$lon,$t?units=si&exclude=currently,hourly,flags" > "$json"
w_sum=$(jq '.daily | .data | .[0] | .summary' "$json" | tr -d '"')
w_temp=$(jq '.daily | .data | .[0] | .temperatureHigh' "$json" | tr -d '"')
exiftool -overwrite_original -copyright="$copyright" -comment="$camera, $lens, $w_temp°C, $w_sum" "$file"
......@@ -172,14 +180,17 @@ echo "--------------------------"
echo "Renaming and organizing..."
echo "--------------------------"
echo
exiftool -r -d %Y%m%d-%H%M%S%%-c.%%e '-FileName<DateTimeOriginal' "$target"
exiftool -r '-Directory<CreateDate' -d ./%Y-%m-%d "$target"
exiftool -d %Y%m%d-%H%M%S%%-c.%%e '-FileName<DateTimeOriginal' "$target"
exiftool '-Directory<CreateDate' -d ./%Y-%m-%d "$target"
if [ -f "$json" ]; then
rm "$json"
fi
cd
find "$target" -type d -exec chmod 755 {} \;
if [ ! -z "$notify_token" ]; then
curl -k \
"https://us-central1-notify-b7652.cloudfunctions.net/sendNotification?to=${notify_token}&text=Momo%20is%20done!" \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment