convert method

  1. @override
bool convert()

Implementation

@override
bool convert() {
  int start = bytes.length - ID3V1Decoder.inherentTotalLength;
  if (start < 0 || readValue(fragments[0], start) != 'TAG') {
    return false;
  }
  // Range
  metadata.setRangeStart(start);
  metadata.setRangeLength(totalLength);

  final codec = ByteCodec();

  metadata.set(value: version, key: "Version");
  start += fragments[0].length;

  // Title
  final titleBytes = bytes.sublist(start, start + 30);
  metadata.set(value: codec.decode(titleBytes), key: 'Title');
  start += 30;

  // Artist
  final artistBytes = bytes.sublist(start, start + 30);
  metadata.set(value: codec.decode(artistBytes), key: 'Artist');
  start += 30;

  // Album
  final albumBytes = bytes.sublist(start, start + 30);
  metadata.set(value: codec.decode(albumBytes), key: 'Album');
  start += 30;

  // Year
  final yearBytes = bytes.sublist(start, start + 4);
  metadata.set(value: codec.decode(yearBytes), key: 'Year');
  start += 4;

  // Comment (30 or 28)
  final hasReserve = bytes.sublist(start + 28, start + 29).first != 0x00;
  if (hasReserve) {
    // ID3V1.1
    metadata.set(value: 'V1.1', key: "Version");

    final commentBytes = bytes.sublist(start, start + 28);
    metadata.set(value: codec.decode(commentBytes), key: 'Comment');
    start += 28;

    // Reserve
    final reserveBytes = bytes.sublist(start, start + 1).first;
    metadata.set(value: reserveBytes, key: 'Reserve');
    start += 1;

    // Track
    final trackBytes = bytes.sublist(start, start + 1).first;
    metadata.set(value: trackBytes, key: 'Track');
    start += 1;
  } else {
    final commentBytes = bytes.sublist(start, start + 30);
    metadata.set(value: codec.decode(commentBytes), key: 'Comment');
    start += 30;
  }

  // Genre
  // Index in a list of genres, or 255
  final genre = bytes.sublist(start, start + 1).first;
  if (genre == 255) {
    metadata.set(value: 'Default', key: 'Genre');
  } else {
    if (genre >= genreList.length) {
      metadata.set(value: 'Unknown', key: 'Genre');
    } else {
      metadata.set(value: genreList[genre], key: 'Genre');
    }
  }
  start += 1;

  return true;
}