Skip to content

Commit

Permalink
Handle compressed xcf files & with quotes
Browse files Browse the repository at this point in the history
Handle legacy compressed xcf files. Make sure that file names with
embedded double quotes are properly handled.
  • Loading branch information
dfandrich committed May 16, 2024
1 parent 090ebda commit b4fa1c1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
10 changes: 7 additions & 3 deletions autodescribe
Original file line number Diff line number Diff line change
Expand Up @@ -1275,10 +1275,14 @@ comment_xbm () {
# File type: xcf (Gimp image)
# requires: gimp
comment_xcf () {
# "safe" filename with quoted double quotes
sf="$(echo "$1" | sed 's/"/\\"/g')"
# gimp's Scheme interpreter displays some logging info before and after the
# desired output, so use sed to delete it to leave only XML.
METADATA=$(echo '((display "\nMETADATA-START\n") (let ((img (car (gimp-file-load 1 "'"$1"'" "file")))) (display (car (gimp-image-get-metadata img))) (gimp-image-delete img)) (gimp-quit TRUE))' | gimp -n -i -d -f -s -g /dev/null --stack-trace-mode=never -b - 2>/dev/null | sed -e '1,/^METADATA-START/d' -e '/<\/metadata>/q')
COMMENT=$(echo "$METADATA" | xmlstarlet sel -t -v '/metadata/tag[@name="Xmp.dc.title"]' | sed 's/lang="x-default" *//')
METADATA=$(echo '((display "\nMETADATA-START\n") (let ((img (car (gimp-file-load RUN-NONINTERACTIVE "'"$sf"'" "file")))) (display (car (gimp-image-get-metadata img))) (gimp-image-delete img)) (gimp-quit TRUE))' | gimp -n -i -d -f -s -g /dev/null --stack-trace-mode=never -b - 2>/dev/null | sed -e '1,/^METADATA-START/d' -e '/<\/metadata>/q')
if [ -n "$METADATA" ]; then
COMMENT=$(echo "$METADATA" | xmlstarlet sel -t -v '/metadata/tag[@name="Xmp.dc.title"]' | sed 's/lang="x-default" *//')
fi
}

# File type: xpm (X pixmap image)
Expand Down Expand Up @@ -1615,7 +1619,7 @@ for f in "$@" ; do
*.xbm)
TYPE=xbm
;;
*.xcf)
*.xcf | *.xcf.gz | *.xcf.bz2 | *.xcf.xz | *.xcfgz | *.xcfbz2 | *.xcfxz)
TYPE=xcf
;;
*.xhb)
Expand Down
14 changes: 9 additions & 5 deletions automtime
Original file line number Diff line number Diff line change
Expand Up @@ -817,14 +817,18 @@ mtime_wml () {
# File type: xcf (Gimp image)
# requires: gimp
mtime_xcf () {
# "safe" filename with quoted double quotes
sf="$(echo "$1" | sed 's/"/\\"/g')"
# The mtime is considered to be the most recent stored event, which is
# generally a "save" event (which makes sense).
# gimp's Scheme interpreter displays some logging info before and after the
# desired output, so use sed to delete it to leave only XML.
METADATA=$(echo '((display "\nMETADATA-START\n") (let ((img (car (gimp-file-load 1 "'"$1"'" "file")))) (display (car (gimp-image-get-metadata img))) (gimp-image-delete img)) (gimp-quit TRUE))' | gimp -n -i -d -f -s -g /dev/null --stack-trace-mode=never -b - 2>/dev/null | sed -e '1,/^METADATA-START/d' -e '/<\/metadata>/q')
RAWTIME=$(echo "$METADATA" | xmlstarlet sel -t -v "/metadata/tag[starts-with(@name, 'Xmp.xmpMM.History[') and contains(@name, '/stEvt:when')]" | sed 's/lang="x-default" *//' | sort -d | tail -1)
# $RAWTIME is like 2022-02-23T22:50:48-08:00
TIME="$(normalize_iso_time "$RAWTIME")"
METADATA=$(echo '((display "\nMETADATA-START\n") (let ((img (car (gimp-file-load RUN-NONINTERACTIVE "'"$sf"'" "file")))) (display (car (gimp-image-get-metadata img))) (gimp-image-delete img)) (gimp-quit TRUE))' | gimp -n -i -d -f -s -g /dev/null --stack-trace-mode=never -b - 2>/dev/null | sed -e '1,/^METADATA-START/d' -e '/<\/metadata>/q')
if [ -n "$METADATA" ]; then
RAWTIME=$(echo "$METADATA" | xmlstarlet sel -t -v "/metadata/tag[starts-with(@name, 'Xmp.xmpMM.History[') and contains(@name, '/stEvt:when')]" | sed 's/lang="x-default" *//' | sort -d | tail -1)
# $RAWTIME is like 2022-02-23T22:50:48-08:00
TIME="$(normalize_iso_time "$RAWTIME")"
fi
if [ -z "$TIME" ]; then
# Gimp probably isn't installed; maybe exiftool is
mtime_xcf_exiftool "$1"
Expand Down Expand Up @@ -1180,7 +1184,7 @@ for f in "$@" ; do
TYPE=wml
;;

*.xcf)
*.xcf | *.xcf.gz | *.xcf.bz2 | *.xcf.xz | *.xcfgz | *.xcfbz2 | *.xcfxz)
TYPE=xcf
;;

Expand Down

0 comments on commit b4fa1c1

Please sign in to comment.