getLiveVideos method Null safety

  1. @override
Future<VideoFullList> getLiveVideos(
  1. {String? channelId,
  2. List<Includes> includes = const [Includes.liveInfo],
  3. List<Language> languages = const [Language.all],
  4. int limit = 9999,
  5. int? maxUpcomingHours = 48,
  6. String? mentionedChannelId,
  7. int offset = 0,
  8. Order order = Order.ascending,
  9. List<String>? organization,
  10. bool paginated = true,
  11. List<VideoSort> videoSort = const <VideoSort>[VideoSort.availableAt],
  12. List<VideoStatus>? videoStatus = const [VideoStatus.live, VideoStatus.upcoming],
  13. String? topic,
  14. VideoType? videoType = VideoType.stream}
)

Get a list of live videos

Returns VideoFullList

This is somewhat similar to calling listVideos().

However, this endpoint imposes these default values on the query parameters: You can choose to override them by providing your own values.

status: [VideoStatus.live, VideoStatus.upcoming],
type: VideoType.stream,
sort: [VideoSort.availableAt],
order: Order.ascending,
max_upcoming_hours: 48,
limit: 9999,
include: [Includes.liveInfo] + query's include

Arguments:

  • channelId Filter by video uploader channel ID
  • includes Request extra data be included in the results. They are not guarenteed to be returned.
  • languages Filter by the Language
  • limit Limit the number of results returned.
  • maxUpcomingHours Number of maximum hours upcoming to get upcoming videos by (for rejecting waiting rooms that are two years out)
  • mentionedChannelId Filter by mentioned channel id, excludes itself. Generally used to find collabs/clips that include the requested channel
  • offset Receive results starting at this number in the array from the Holodex API
  • order Order by ascending or descending
  • organization Filter by clips that feature the org's talent or videos posted by the org's talent.
  • paginated If paginated is set to true, returns VideoFullList with total, otherwise returns VideoFullList without the total.
  • videoSort Sort the returned data by this field
  • videoStatus Filter by the video status
  • topic Filter by video topic ID
  • videoType Filter by type of video, either clips or streams

Implementation

@override
Future<VideoFullList> getLiveVideos({
  String? channelId,
  List<Includes> includes = const [Includes.liveInfo],
  List<Language> languages = const [Language.all],
  int limit = 9999,
  int? maxUpcomingHours = 48,
  String? mentionedChannelId,
  int offset = 0,
  Order order = Order.ascending,
  List<String>? organization,
  bool paginated = true,
  List<VideoSort> videoSort = const <VideoSort>[VideoSort.availableAt],
  List<VideoStatus>? videoStatus = const [
    VideoStatus.live,
    VideoStatus.upcoming
  ],
  String? topic,
  VideoType? videoType = VideoType.stream,
}) async {
  // Create the params list
  final Map<String, dynamic> params = {};

  // Make sure liveInfo is in the list
  if (!includes.contains(Includes.liveInfo)) {
    includes.add(Includes.liveInfo);
  }

  // Add the items with default values (they can't be null)
  params.addAll({
    'limit': '$limit',
    'offset': '$offset',
    'order': EnumUtil.convertOrderToString(order),
  });

  _addVideoSort(videoSort, params);

  _addPaginated(paginated, params);

  _addChannelId(channelId, params);

  // Add the info the videos must include
  _addIncludes(includes, params);

  // Add the languages to filter by
  // Add the first item so that there is not a comma in front
  _addLanguages(languages, params);

  // Add the max upcoming hours param
  _addMaxUpcomingHours(maxUpcomingHours, params);

  // Add the mentioned channel id param
  _addMentionedChannelId(mentionedChannelId, params);

  // Add the organization param
  _addOrganizations(organization, params);

  // Add the topic param
  _addTopic(topic, params);

  // Add the status param
  _addStatusList(videoStatus, params);

  // Add the type param
  _addType(videoType, params);

  final response = await get(path: _Constants.liveVideosPath, params: params);

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

  final List list = jsonDecode(response.body);
  return VideoFullList(
      videos: list
          .map((video) => VideoFull.fromMap(video))
          .toList()); // Returns as `List<Video>`
}