getManifest method

Future<StreamManifest> getManifest(
  1. dynamic videoId, {
  2. bool fullManifest = false,
})

Gets the manifest that contains information about available streams in the specified video.

If fullManifest is set to true, more streams types will be fetched and track of different languages (if present) will be included.

Implementation

Future<StreamManifest> getManifest(dynamic videoId,
    {bool fullManifest = false}) {
  videoId = VideoId.fromString(videoId);

  return retry(_httpClient, () async {
    final streams =
        await _getStreams(videoId, fullManifest: fullManifest).toList();
    if (streams.isEmpty) {
      throw VideoUnavailableException(
        'Video "$videoId" does not contain any playable streams.',
      );
    }

    final response = await _httpClient.head(streams.first.url);
    if (response.statusCode == 403) {
      throw YoutubeExplodeException(
        'Video $videoId returned 403 (stream: ${streams.first.tag}',
      );
    }

    // Remove duplicate streams (must have same tag and audioTrack (if it's an audio stream))
    final uniqueStreams = LinkedHashSet<StreamInfo>(
      equals: (a, b) {
        if (a.runtimeType != b.runtimeType) return false;
        if (a is AudioStreamInfo && b is AudioStreamInfo) {
          return a.tag == b.tag && a.audioTrack == b.audioTrack;
        }
        return a.tag == b.tag;
      },
      hashCode: (e) {
        if (e is AudioStreamInfo) {
          return e.tag.hashCode ^ e.audioTrack.hashCode;
        }
        return e.tag.hashCode;
      },
    );
    uniqueStreams.addAll(streams);

    return StreamManifest(uniqueStreams.toList());
  });
}