#!/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