mp3agic icon indicating copy to clipboard operation
mp3agic copied to clipboard

Support for text information frames with multiple strings in ID3v2.4

Open mpatric opened this issue 12 years ago • 11 comments

ID3v2.4 text information frames can contain multiple strings, whereas in ID3v2.3 and earlier they can only contain one. From the ID3v2.4 specification:

The text information frames are often the most important frames,
containing information like artist, album and more. There may only be
one text information frame of its kind in an tag. All text
information frames supports multiple strings, stored as a null
separated list, where null is reperesented by the termination code
for the charater encoding. All text frame identifiers begin with "T".
Only text frame identifiers begin with "T", with the exception of the
"TXXX" frame. All the text information frames have the following
format:

  <Header for 'Text information frame', ID: "T000" - "TZZZ",
  excluding "TXXX" described in 4.2.6.>
  Text encoding                $xx
  Information                  <text string(s) according to encoding>

Mp3agic will currently only return the first value when reading multi-values text information frames and will only allow you to set one value.

mpatric avatar Jul 09 '13 08:07 mpatric

Any thoughts on implementing this? I might take a stab at it soon; any guidance would be helpful.

gardnermj avatar Dec 25 '13 13:12 gardnermj

I've implemented multi-value support for ID3v2.4 text frames: https://github.com/oueqzoms/mp3agic/commit/c06d8da0b24969b98f41b90fdb06048dfac691df. Before I start working on tests, could you let me know what you think of the API changes?

gardnermj avatar Dec 31 '13 01:12 gardnermj

Hi, sorry for the slow response, I've been away from a good internet connection for the last week.

The approach you've taken is the same as what I was thinking; i.e. you've added various plural versions of the get and set methods to the ID3v24 interface that return/take arrays of Strings instead of Strings.

Thanks for working on this.

Cheers, Michael

mpatric avatar Dec 31 '13 15:12 mpatric

Thanks for the feedback. Do you have any opinion on what type of collection the plurals should return? I used String[] because it was convenient, but I'm rusty with Java and don't know the current best practice for returning ordered collections.

gardnermj avatar Dec 31 '13 19:12 gardnermj

I prefer native arrays, i.e. String[]. Does anyone else have an opinion on native array vs a collection interface? @hennr - do you have an opinion on this?

mpatric avatar Jan 01 '14 13:01 mpatric

Hi @oueqzoms thanks for implementing this!

I'm fine with String arrays as well, but for the setters I'd prefer varargs e.g. public void setArtists(String[] artists) { should become public void setArtists(String... artists) {

Also please avoid checked exception where possible, they are unhandy to code with.

hennr avatar Jan 06 '14 21:01 hennr

@hennr, varargs would make it awkward to provide values from a collection, which seems likely to be the most common scenario. That doesn't feel like a good trade-off to me.

About the checked exceptions, I just followed the existing method signatures. I have no opinion on that, other than that things should be kept consistent either way.

gardnermj avatar Jan 06 '14 22:01 gardnermj

Would it be better to put the plural getters in the ID3v2 interface, so that ID3v2.x tags can all be read in a consistent way?

The non-2.4 implementations would just return 1-element arrays (even though technically some text frames in ID3v2.3 do support multiple values separated by a forward slash, that just seems too error-prone to support at this level due to false positives like "AC/DC").

gardnermj avatar Jan 06 '14 23:01 gardnermj

I like your suggestion about plural getters in the ID3v2 interface, with the pre 2.4 implementations returning 1-element arrays.

mpatric avatar Jan 07 '14 10:01 mpatric

After some more thought, I would now advocate having the plurals use Iterable<String>. But if the consensus is still for String[], that's fine too.

In the event that there is no corresponding frame, should the plural getters return null or an empty collection? I'd lean towards the empty collection, to reduce null-checking by clients.

gardnermj avatar Jan 09 '14 20:01 gardnermj

I'd prefer an empty collection for the same reason.

hennr avatar Jan 09 '14 21:01 hennr