getVideoMetadata method Null safety

  1. @override
Future<VideoMetadata> getVideoMetadata(
  1. String videoId,
  2. {bool timestampComments = false,
  3. List<Language>? recommendationLanguages}
)

Retrieves a video

Retrieves Comments if timestampComments is set to true

Retrieves Recommendations if query parameter recommendationLanguages is set

Arguments

  • videoId ID of the video
  • timestampComments If set to true, comments with timestamps will be returned
  • recommendationLanguages If set, videos matching the languages will be returned. Use Language.all to get all languages regardless of language

Implementation

@override
Future<VideoMetadata> getVideoMetadata(
  String videoId, {
  bool timestampComments = false,
  List<Language>? recommendationLanguages,
}) async {
  final Map<String, dynamic> params = {};

  _addLanguages(recommendationLanguages, params);

  _addCommentsFlag(timestampComments, params);

  final response = await get(path: '${_Constants.videosPath}/$videoId', params: params);
  final body = jsonDecode(response.body);
  final video = VideoFull.fromMap(body);
  final List? comments = body['comments'];
  final List? recommendations = body['recommendations'];
  return VideoMetadata(
    video: video,
    comments: comments?.map((comment) => Comment.fromMap(comment)).toList(),
    recommendations: recommendations?.map((video) => Video.fromMap(video)).toList(),
  );
}