adding xml2jpg

This commit is contained in:
tengel 2024-03-20 11:28:46 -05:00
parent fa55d1f2f1
commit 42f6e848bb

28
shell/xml2jpg.sh Executable file
View file

@ -0,0 +1,28 @@
#!/usr/bin/env bash
#
# Read XML from Flickr and rename corresponding files to 'taken' date
# requires xml2 and jhead RPMs
#
# SPDX-License-Identifier: MIT
for file in *.xml; do
FNAME="${file%.*}"
if [ ! -e "${FNAME}.jpg" ]; then
continue
fi
echo "Inspecting $file"
JPGDT=$(xml2 < "$file" | grep "@taken=" | cut -f2 -d '=')
if [ "X${JPGDT}" == "X" ]; then
echo "Empty Date/Time."
continue
else
BASE=$(date -d "$JPGDT" +"FLICKR_%Y%m%d_%H%M%S")
if [ ! -e "${BASE}.jpg" ]; then
echo "New file: ${BASE}.jpg"
mv "${FNAME}.jpg" "${BASE}.jpg"
touch -d "${JPGDT}" "${BASE}.jpg"
jhead -mkexif -dsft "${BASE}.jpg"
rm -f "${file}"
fi
fi
done