getChannelRelatedVideos method

Future<PaginatedVideos> getChannelRelatedVideos(
  1. String channelId, {
  2. required VideoSearchType type,
  3. ChannelVideoFilter filter = const ChannelVideoFilter(),
})

Get Videos Related To Channel

A simplified method for access channel specific data. If you want more customization, the same result can be obtained by calling the getVideos method.

Arguments

  • channelId ID of the Youtube Channel that is being queried
  • type The type of video resource to fetch. Clips finds clip videos of a vtuber channel, Video finds the channelId channel's uploads, and collabs finds videos uploaded by other channels that mention this channelId
  • filter Filter the results returns by the API

Implementation

Future<PaginatedVideos> getChannelRelatedVideos(
  String channelId, {
  required VideoSearchType type,
  ChannelVideoFilter filter = const ChannelVideoFilter(),
}) async {
  final Map<String, dynamic> params = filter.toJson();
  final response = await get(
      path: '${HolodexEndpoint.channels}/$channelId/${type.code}',
      params: params);

  if (filter.paginated) {
    // Grab total and return with it
    final videoList = PaginatedVideos.fromString(response.body);
    return videoList.copyWith(paginated: true);
  }

  final List<dynamic> list = jsonDecode(response.body);
  return PaginatedVideos(
    items: list.map((video) => VideoFull.fromJson(video)).toList(),
  );
}