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.
parent 46f376e4
...@@ -489,12 +489,9 @@ public final class Id3Decoder extends SimpleMetadataDecoder { ...@@ -489,12 +489,9 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
ArrayList<String> values = new ArrayList<>(); ArrayList<String> values = new ArrayList<>();
if (index >= data.length) { 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); String charset = getCharsetName(encoding);
int valueStartIndex = index; int valueStartIndex = index;
int valueEndIndex = indexOfTerminator(data, valueStartIndex, encoding); int valueEndIndex = indexOfTerminator(data, valueStartIndex, encoding);
...@@ -506,8 +503,12 @@ public final class Id3Decoder extends SimpleMetadataDecoder { ...@@ -506,8 +503,12 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
valueEndIndex = indexOfTerminator(data, valueStartIndex, encoding); valueEndIndex = indexOfTerminator(data, valueStartIndex, encoding);
} }
if (values.isEmpty()) {
return Collections.singletonList("");
} else {
return values; return values;
} }
}
@Nullable @Nullable
private static UrlLinkFrame decodeWxxxFrame(ParsableByteArray id3Data, int frameSize) private static UrlLinkFrame decodeWxxxFrame(ParsableByteArray id3Data, int frameSize)
......
...@@ -36,19 +36,18 @@ public final class TextInformationFrame extends Id3Frame { ...@@ -36,19 +36,18 @@ public final class TextInformationFrame extends Id3Frame {
@Deprecated @Deprecated
public final String value; public final String value;
/** The text values of this frame. Will always have at least one element. */
@NonNull @NonNull
public final List<String> values; public final List<String> values;
public TextInformationFrame(String id, @Nullable String description, @NonNull List<String> values) { public TextInformationFrame(String id, @Nullable String description, @NonNull List<String> values) {
super(id); super(id);
this.description = description; if (values.isEmpty()) {
throw new IllegalArgumentException("Text information frames must have at least one value");
if( values.size() > 0 ) {
this.values = ImmutableList.copyOf(values);
} else {
this.values = ImmutableList.of("");
} }
this.description = description;
this.values = ImmutableList.copyOf(values);
this.value = this.values.get(0); this.value = this.values.get(0);
} }
......
...@@ -109,21 +109,5 @@ public class TextInformationFrameTest { ...@@ -109,21 +109,5 @@ public class TextInformationFrameTest {
assertThat(mediaMetadata.composer.toString()).isEqualTo(composer); assertThat(mediaMetadata.composer.toString()).isEqualTo(composer);
assertThat(mediaMetadata.conductor.toString()).isEqualTo(conductor); assertThat(mediaMetadata.conductor.toString()).isEqualTo(conductor);
assertThat(mediaMetadata.writer.toString()).isEqualTo(writer); 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("");
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment