Want to get back to using exiv2 executable, but...

Added by Steve Wright 14 days ago

...it's been years since I've written a (bash) script to add a "flexible" number of keywords to a JPEG file.

By "flexible" I mean: unknown before the script is run.

The script I've been using, which was originally written for Exiftool, is attached with some recently commented-out code (function twokey)returned to execution.

I've consulted linuxquestions.org, but they can only give me pointers on the bash part of the code. I need a "second pair of eyes" to check what might be wrong with the Exiv2 parts.

BZT
Great to be back.

addkeys.sh.txt Magnifier (1.13 KB)


Replies (8)

RE: Want to get back to using exiv2 executable, but... - Added by Robin Mills 14 days ago

How nice to hear from you. Gosh, it's been a while. 2012 maybe? Since we last spoke, I've retired and returned from Silicon Valley to my home in England.

We released Exiv2 v0.27 RC1 last Friday:

http://dev.exiv2.org/boards/3/topics/2830
http://exiv2.dyndns.org

I highly recommend the O'Reilly Book "Learning the bash shell". Bash is very useful. It takes a while to learn. Well worth the effort.

Can you explain what this does? It goes crazy on my laptop and shows lots of binary data. You're adding key/value pairs to something in IPTC. Can you give me a couple of files before/after running this and I'll see what you're doing.

I've tidied your code to make it easier to read and reordered the functions (declare them, then use them).

#!/bin/bash

function twokey () {
    taxt=$(echo "$k" | cut -d, -f2)
    keycount=$(echo "$k" | tr ',' ' ' | wc -w)
    for keys in $(echo "$k" | tr ',' ' ' | wc -w)
    do
        echo "${keys}" 
        exiv2 --keep -M"add Iptc.Application2.Keywords $taxt" -M"add Xmp.dc.subject $taxt" "$f" 
        ((taxt++))
    done
    exiv2 -g Iptc.Application2.Keywords -Pv "$f" 
}

function dothedeed () {
    echo -e "Adding Keywords to \e[5;42m$f\e[0m." 
    echo -e "$f\t$k" 
    keycount=$(echo "$k" | tr ',' ' ' | wc -w)
    echo "$f: There are $keycount keywords." 
    echo "Here's the Keyword string." 
    echo -e "$k" 
    exiftool -sep "," -fast5 -overwrite_original_in_place -q -P -Keywords+="$k" -Subject+="$k" "$f" 
    twokey
}

function dav () {
    echo -e "What text file will I be using?" 
    read -er item
    f=$item
    while IFS="^" read -r f k
    do
        echo -e "File is \e[31m$f\e[0m" 
        if [[ ! -f "$f" ]]; then
            echo "I don't see $f in this directory." 
            echo "Moving to next list item." 
            continue
        fi
        dothedeed
    done<"$f" 
}

dav

# That's all Folks!
##

RE: Want to get back to using exiv2 executable, but... - Added by Robin Mills 14 days ago

By the way, I love this line of code:

echo "I don't see $f in this directory."

RE: Want to get back to using exiv2 executable, but... - Added by Steve Wright 10 days ago

Yes, that is a precious one, isn't it.

Good to hear you're back in England. Funny thing .. I just sent Andreas an email asking where you were. I should have logged in here and checked this thread instead.

Always going for the long, hard route to a solution, me. Linux (currently running Kubuntu 17.04) is treating me well, and vice versa. Do you know if there are .debs available on dyndyns.org? As before I'm not keen on installing from scratch unless I absolutely must. Ubuntu's repositories bring us Exiv2 users up to 0.25, which is OK with me; I can wait until I upgrade to Ku-18 (available but I must backup -- about 75 GB -- before I install it). I'm sure it's in the repos for the newer versions.

Steve W

RE: Want to get back to using exiv2 executable, but... - Added by Robin Mills 10 days ago

We could produce debs, I think. Thanks to Luis, we have now 100% adopted CMake as our build infrastructure on all platforms. CMake has a companion CPack for creating packages and we're using that to create the source and binary bundles for the web site. It's reasonable to believe that CPack could produce what you want. However, as you know, everything takes time and Luis and I have been working long days recently. Extending the scope of the project is impossible if we're going to make Exiv2 v0.27 GM for Christmas (and we will).

I believe ubuntu-18.04 LTS (which I run on my machines) has Exiv2 v0.25. I had a discussion with a darktable user during the week and concluded that we're still stuck in the dark ages!

RE: Want to get back to using exiv2 executable, but... - Added by Steve Wright 10 days ago

I tested your revision of my script. The IPTC keyword adding is a bit off; any hyphenated keys get repeated as the last keyword, and the XMP Subject is__ the hyphenated keyword.

Here's a zip with a test picture -- as yet un-keyword-ed --, the script and the keywords I was going to add to it. I'll try get Exiv2 0.27 (probably from an on-web resource), install it and try again.

testpic keys.zip (287 KB)

RE: Want to get back to using exiv2 executable, but... - Added by Steve Wright 10 days ago

Well, I tried installing 0.25 from github. git clone worked OK, but apparently my CMake (which I just now installed) didn't have a default compiler set.
A copy of my output log is attached. Should I get the CMake GUI?

Steve

CMakeOutput.log (39.2 KB)

RE: Want to get back to using exiv2 executable, but... - Added by Steve Wright 3 days ago

Robin,

Even with 0.27 installed, the revised script only writes 1 random keyword, this time to both IPTC Keywords and XMP Subject. I'm at a loss as to how to improve it.

Steve

RE: Want to get back to using exiv2 executable, but... - Added by Robin Mills 3 days ago

I don't know what this script is meant to do. Can you post:

1) An image before and after it runs with exif tool.
I want to know what you're trying to do to the image

2) A transcript of the user experience.
I never use read in scripts. I don't know what that code is attempting to do and it produces a load of binary output on MacOS-X.

Robin

(1-8/8)

Redmine Appliance - Powered by TurnKey Linux