Move ID3v2 text frame fallback to ID3v2 decoder

Instead of the ID3v2 text frame falling back to a singleton list of an
empty string when the given values are empty, make that case throw
an exception within the text frame, and move that fallback behavior
into the ID3v2 decoder.
This commit is contained in:
Alexander Capehart 2022-11-22 09:28:05 -07:00
parent 46f376e40b
commit 85c4d9870b
No known key found for this signature in database
GPG Key ID: 37DBE3621FE9AD47
3 changed files with 12 additions and 28 deletions

View File

@ -489,12 +489,9 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
ArrayList<String> values = new ArrayList<>();
if (index >= data.length) {
return Collections.emptyList();
return Collections.singletonList("");
}
// In ID3v2.4, text information frames can contain multiple values delimited by a null
// terminator. Thus, we after each "end of stream" marker we actually need to keep looking
// for more data, at least until the index is equal to the data length.
String charset = getCharsetName(encoding);
int valueStartIndex = index;
int valueEndIndex = indexOfTerminator(data, valueStartIndex, encoding);
@ -506,8 +503,12 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
valueEndIndex = indexOfTerminator(data, valueStartIndex, encoding);
}
if (values.isEmpty()) {
return Collections.singletonList("");
} else {
return values;
}
}
@Nullable
private static UrlLinkFrame decodeWxxxFrame(ParsableByteArray id3Data, int frameSize)

View File

@ -36,19 +36,18 @@ public final class TextInformationFrame extends Id3Frame {
@Deprecated
public final String value;
/** The text values of this frame. Will always have at least one element. */
@NonNull
public final List<String> values;
public TextInformationFrame(String id, @Nullable String description, @NonNull List<String> values) {
super(id);
this.description = description;
if( values.size() > 0 ) {
this.values = ImmutableList.copyOf(values);
} else {
this.values = ImmutableList.of("");
if (values.isEmpty()) {
throw new IllegalArgumentException("Text information frames must have at least one value");
}
this.description = description;
this.values = ImmutableList.copyOf(values);
this.value = this.values.get(0);
}

View File

@ -109,21 +109,5 @@ public class TextInformationFrameTest {
assertThat(mediaMetadata.composer.toString()).isEqualTo(composer);
assertThat(mediaMetadata.conductor.toString()).isEqualTo(conductor);
assertThat(mediaMetadata.writer.toString()).isEqualTo(writer);
// Test empty value array
entries =
Collections.singletonList(
new TextInformationFrame(/* id= */ "TT2", /* description= */ null, /* values= */ Collections.emptyList())
);
builder = MediaMetadata.EMPTY.buildUpon();
for (Metadata.Entry entry : entries) {
entry.populateMediaMetadata(builder);
}
mediaMetadata = builder.build();
assertThat(mediaMetadata.title.toString()).isEqualTo("");
}
}