exiv2node icon indicating copy to clipboard operation
exiv2node copied to clipboard

Support multiple values with Array

Open dragn opened this issue 10 years ago • 8 comments

Add support to set and get tags with multiple values. getImageTags will return a string for single value or an array of strings for multiple values. setImageTags will add multiple records with the same key when array is provided. Solves #23 I'm just starting to use that in my own project, so any issues may pop up later. Using localized text in tags would certainly impose some difficulties... (Usage of Exiv2::AsciiValue, for example...). I don't really like that part with a lot of copy-paste stuff for ExifData/IptcData/XmpData. But, given that they don't derive from the same class, I have no idea what to do with it (except using macros, which would not do much better).

dragn avatar Jun 28 '15 13:06 dragn

Looking through this, I really like the idea, but I'm wondering if by returning both arrays and strings we'll be breaking backwards compatibility. If people are assuming they'll get a string back and suddenly get an array that's going to cause problems. In that case I'd almost rather just always get an array back rather than having to check the type and then loop or not.

Thoughts?

/cc @dberesford

drewish avatar Jun 30 '15 03:06 drewish

Most of the values are single, so returning array for each value is not very useful. Moreover, if we keep strings for single-value tags, the majority of existing code will still work.

dragn avatar Jun 30 '15 06:06 dragn

Looks good to me, nice job! @drewish I'm happy to merge this, how about you?

dberesford avatar Jun 30 '15 07:06 dberesford

+1

Was just about to submit a bug report. Currently returned Iptc.Application2.Keywords is just the first one, e.g. lightroom, but Xmp.dc.subject and Xmp.lr.hierarchicalSubject are comma-delimited strings, e.g. lightroom, photography, ray shan.

This patch should help.

rayshan avatar Jul 29 '15 07:07 rayshan

@dragn Any chance this could be rebased so it can be merged?

whitelynx avatar Jan 23 '16 02:01 whitelynx

If we do merge this we need to bump the major version since it's not backwards compatible. Also should have an example in the readme since it's a little odd to have to check if it's a string or array. I still think that's going to be a confusing interface.

drewish avatar Jan 24 '16 19:01 drewish

@drewish I think if we'd change it to return (and expect) tags as a single string with comma-separated values, we'd have the same functionality and backward compatibility, except for the fact that you can't use comma in tags...

dragn avatar Jan 25 '16 07:01 dragn

How about an option to choose how multiple values are handled? Something like multipleValuesAsArray: true to get an array back, with the default being a comma-separated list. That way, if you don't mind doing the type checking (and/or have a need to store commas in tags) you can get arrays, but by default it won't break backward compatibility.

whitelynx avatar Feb 05 '16 00:02 whitelynx