getVideos method

Stream<Video> getVideos(
  1. dynamic id
)

Enumerates videos included in the specified playlist.

Implementation

Stream<Video> getVideos(dynamic id) async* {
  id = PlaylistId.fromString(id);
  final encounteredVideoIds = <String>{};
  var prevLength = 0;
  PlaylistPage? page = await PlaylistPage.get(_httpClient, id.value);

  while (page != null) {
    for (final video in page.videos) {
      final videoId = video.id;

      // Already added
      if (!encounteredVideoIds.add(videoId)) {
        continue;
      }

      if (video.channelId.isEmpty) {
        continue;
      }

      yield Video(
        VideoId(videoId),
        video.title,
        video.author,
        ChannelId(video.channelId),
        video.uploadDateRaw.toDateTime(),
        video.uploadDateRaw,
        null,
        video.description,
        video.duration,
        ThumbnailSet(videoId),
        null,
        Engagement(video.viewCount, null, null),
        false,
      );
    }
    if (encounteredVideoIds.length == prevLength) {
      break;
    }
    prevLength = encounteredVideoIds.length;
    page = await page.nextPage(_httpClient);
  }
}