search method

Future<YoutubeSearchVideos> search({
  1. required String query,
})

Implementation

Future<googleapis_client_scheme.YoutubeSearchVideos> search({
  required String query,
}) async {
  VideoSearchList videoSearchList = await youtubeExplode.search.search(query);

  List<Map> jsonDataVideos = videoSearchList.map((Video video) {
    Map jsonDataVideo = {
      "@type": "youtubeVideo",
      "id": video.id.value,
      "author": video.author,
      "channel_id": video.channelId.value,
      "title": video.title,
      "description": video.description,
      "url": video.url,
      "duration": video.duration?.toString(),
      "date": video.uploadDate?.millisecondsSinceEpoch,
      "has_watch_page": video.hasWatchPage,
      "is_live": video.isLive,
      "keywords": video.keywords.toList(),
      "engagement": {
        "@type": "youtubeVideoEngagement",
        "average_count": video.engagement.avgRating,
        "dislike_count": video.engagement.dislikeCount,
        "like_count": video.engagement.likeCount,
        "view_count": video.engagement.viewCount,
      },
      "thumbnails": {
        "@type": "youtubeVideoThumbnails",
        "low": video.thumbnails.lowResUrl,
        "medium": video.thumbnails.mediumResUrl,
        "high": video.thumbnails.highResUrl,
        "max": video.thumbnails.maxResUrl,
        "standard": video.thumbnails.standardResUrl,
      },
    };
    return jsonDataVideo;
  }).toList();
  Map jsonData = {
    "@type": "youtubeSearchVideos",
    "count": videoSearchList.length,
    "videos": jsonDataVideos,
  };

  return googleapis_client_scheme.YoutubeSearchVideos(jsonData);
}