Want to get back to using exiv2 executable, but...
Added by Steve Wright about 3 years 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 (1.13 KB) addkeys.sh.txt |
Replies (12)
RE: Want to get back to using exiv2 executable, but... - Added by Robin Mills about 3 years 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 about 3 years 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 about 3 years 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 about 3 years 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 about 3 years 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) testpic keys.zip |
RE: Want to get back to using exiv2 executable, but... - Added by Steve Wright about 3 years 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) CMakeOutput.log |
RE: Want to get back to using exiv2 executable, but... - Added by Steve Wright about 3 years 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 about 3 years 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
RE: Want to get back to using exiv2 executable, but... - Added by Steve Wright about 3 years ago
As the current announcement thread on 0.27 RC1 is locked, I'll make this announcement here, for the benefit of new users of the product.
Robin emailed me earlier today (15-11) to say RC2 is going to be released to the usual places (github and dyndyns.org) tomorrow. He didn't say what the specific changes or fixes were, but I'm sure there are as many of those as there were with RC1.
Steve Wright
RE: Want to get back to using exiv2 executable, but... - Added by Robin Mills about 3 years ago
Thanks Steve. We've had very good feedback on RC1 and dealt with everything reported. The fixes are listed in releasenotes.txt
I am really pleased with Exiv2 v0.27. It's the best tested and documented release of Exiv2. This is thanks to Luis and Dan who have done outstanding work. With more folks working on Exiv2, I've had time to improve the release process and the web site.
The release should be available on http://exiv2.dyndns.org by 21:00GMT on 2018-11-16
RE: Want to get back to using exiv2 executable, but... - Added by Steve Wright about 3 years ago
Finally working
Thanks again to Robin.
For anyone curious as to the changes, here's the whole script (unworkable parts edited out):
#!/bin/bash function twokey () { keycount=$(echo "$k" | tr ',' ' ' | wc -w) echo "$f: There are $keycount keywords." IFS=, for ky in $k do exiv2 --keep -M"add Iptc.Application2.Keywords $ky" -M"add Xmp.dc.subject $ky" "$f" echo "Adding keyword $ky" done returned=$(exiv2 -g Iptc.Application2.Keywords -Pv "$f" | tr '\n' ',' | sed "s/,$//") } 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 twokey done<"$f" } dav
RE: Want to get back to using exiv2 executable, but... - Added by Robin Mills about 3 years ago
I'm still totally baffled about what this is meant to do and it produces lots of binary output on the terminal.
I've written something that sort of does what I think you want. I never use bash read, I use the "Software Tools" approach of using command-line arguments.
$ curl -O http://clanmills.com/Stonehenge.jpg % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 6599k 100 6599k 0 0 686k 0 0:00:09 0:00:09 --:--:-- 1191k $ exiv2 -pa --grep Keywords Stonehenge.jpg $ ./steve.sh name Robin age 67 skill C++ --files Stonehenge.jpg $ exiv2 -pa --grep Keywords Stonehenge.jpg Iptc.Application2.Keywords String 10 name,Robin Iptc.Application2.Keywords String 6 age,67 Iptc.Application2.Keywords String 9 skill,C++ $ ./steve.sh occupation retired --files Stonehenge.jpg $ exiv2 -pa --grep Keywords Stonehenge.jpg Iptc.Application2.Keywords String 10 name,Robin Iptc.Application2.Keywords String 6 age,67 Iptc.Application2.Keywords String 9 skill,C++ Iptc.Application2.Keywords String 18 occupation,retired $
Here's the code in steve.sh
#!/usr/bin/env bash this=$0 syntaxError() { echo "usage: $this [key value]+ --files file ..." exit $1 } if [ "$#" == "0" ]; then syntaxError ; fi declare -a key declare -a value declare -a files N=0 F=0 while [ $# -ne 0 ] ; do case "$1" in -h|--help|-\?) syntaxError 0 ;; --files) shift while [ $# -ne 0 ]; do if [ ! -e $1 ]; then echo $1 does not exist exit 2 fi files[$F]=$1 F=$((F+1)) shift done ;; *)if [ $# -gt 1 ]; then key[$N]=$1; value[$N]=$2; shift 2 else echo "key/value pairs aren't matched" syntaxError 2 fi N=$((N+1)) ;; esac done if [ $F -eq 0 ]; then echo no files given syntaxError 1 fi n=0 while [ $n -ne $N ]; do k=${key[$n]} v=${value[$n]} f=0 while [ $f -ne $F ]; do file=${files[$f]} exiv2 -M"add Iptc.Application2.Keywords $k,$v" "$file" f=$((f+1)) done n=$((n+1)) done # That's all Folks! ##