describe method

String describe()

Print a formatted text of all the streams. Like youtube-dl -F option.

Implementation

String describe() {
  final column = _Column([
    'format code',
    'extension',
    'resolution',
    'quality',
    'bitrate',
    'size',
    'codecs',
    'info'
  ]);
  // Sort the streams:
  // - First audio only streams.
  // - Then sort by resolution.
  // - Then sort by bitrate.
  final sorted = toList()
    ..sort((a, b) {
      final aIsOnlyAudio =
          (a is AudioOnlyStreamInfo) || (a is HlsAudioStreamInfo);
      final bIsOnlyAudio =
          (b is AudioOnlyStreamInfo) || (b is HlsAudioStreamInfo);

      if (aIsOnlyAudio && !bIsOnlyAudio) {
        return -1;
      } else if (!aIsOnlyAudio && bIsOnlyAudio) {
        return 1;
      }

      if (a is VideoStreamInfo && b is VideoStreamInfo) {
        final resolution = a.videoResolution.compareTo(b.videoResolution);
        if (resolution != 0) {
          return resolution;
        }
      }
      return a.bitrate.compareTo(b.bitrate);
    });

  for (final e in sorted) {
    column.write([
      e.tag,
      e.container.name,
      if (e is VideoStreamInfo) e.videoResolution else 'audio only',
      if (e is VideoStreamInfo)
        '${e.qualityLabel}${e.framerate.framesPerSecond}'
      else
        e.qualityLabel,
      '${e is HlsStreamInfo ? '~' : ''}${e.bitrate}',
      '${e is HlsStreamInfo ? '~' : ''}${e.size}',
      e.codec.parameters['codecs'],
      if (e is VideoOnlyStreamInfo || e is HlsVideoStreamInfo) 'video only',
      // if (e is AudioOnlyStreamInfo) 'audio only',
      if (e is MuxedStreamInfo || e is HlsMuxedStreamInfo) 'muxed',
      if (e case AudioStreamInfo(:AudioTrack audioTrack))
        audioTrack.displayName,
    ]);
  }
  return column.toString();
}