YtVideo.fromJson constructor

YtVideo.fromJson(
  1. JsonMap jsonData
)

Implementation

factory YtVideo.fromJson(JsonMap jsonData) {
  final String? id = jsonData['videoId'] as String?;
  return YtVideo(
    thumbnailData: YtThumbnailData.fromJson(
      List<JsonMap>.from(jsonData['thumbnails'] as List),
    ),
    id: id,
    title: jsonData['title'] as String,
    videoType: VideoType.fromValue(jsonData['videoType'] as String?),
    durationRaw: jsonData['duration'] as String?,
    duration:
        jsonData['duration_seconds'] is int
            ? Duration(seconds: jsonData['duration_seconds'] as int)
            : null,
    artists:
        List<JsonMap>.from(jsonData['artists'] as List)
            .map((artist) => YtBaseObject.fromJson(artist, 'id', 'name'))
            .toList(),
    views: jsonData['views'] as String?,
    year:
        (jsonData['year'] is int)
            ? (jsonData['year'] as int)
            : ((jsonData['year'] is String)
                ? (int.tryParse(jsonData['year'] as String))
                : null),
    isAvailable:
        (jsonData['isAvailable'] as bool?) == null
            ? (id != null)
            : jsonData['isAvailable'] as bool && (id != null),
  );
}