getChannelVideos method
Implementation
Future<googleapis_client_scheme.YoutubeChannelVideos> getChannelVideos({
required String channel,
}) async {
googleapis_client_scheme.YoutubeSchemaText youtubeSchemaText =
GoogleApisClientUtils.parseTextToYoutube(text: channel);
if (youtubeSchemaText["@type"] == "error") {
return googleapis_client_scheme.YoutubeChannelVideos(
youtubeSchemaText.rawData);
}
String channel_id = await () async {
if (youtubeSchemaText.type != "channel_id") {
return (await getChannel(channel: channel)).id ?? "";
}
return channel;
}.call();
final List<Video> videos =
await youtubeExplode.channels.getUploads(channel_id).toList();
List<Map> jsonDataVideos = videos.map((Video video) {
final 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();
final Map jsonData = {
"@type": "youtubeChannelVideos",
"count": videos.length,
"videos": jsonDataVideos,
};
return googleapis_client_scheme.YoutubeChannelVideos(jsonData);
}