private PlatformStreamsDto ToStreams( YouTubeSearchDto streams, Dictionary <string, YouTubeChannelSnippetDto> channelSnippets, Dictionary <string, YouTubeVideoLiveStreamingDetailsDto> liveStreamDetails) { return(new PlatformStreamsDto { StreamPlatformName = StreamPlatform.YouTube, Streams = streams.items.Select(v => { var viewers = liveStreamDetails.ContainsKey(v.id.videoId) ? liveStreamDetails[v.id.videoId].concurrentViewers : 0; var avatarUrl = channelSnippets.ContainsKey(v.snippet.channelId) ? channelSnippets[v.snippet.channelId][email protected] : null; return new PlatformStreamDto { StreamerName = v.snippet.channelTitle, StreamTitle = v.snippet.title, StreamThumbnailUrl = v.snippet.thumbnails.medium.url, StreamerAvatarUrl = avatarUrl, StreamUrl = $"{youTubeWebUrl}/watch?v={v.id.videoId}", IsLive = true, Views = viewers, }; }), NextPageToken = streams.nextPageToken ?? string.Empty, }); }
public YouTubeSearchDto Build() { var youTubeSearchDto = new YouTubeSearchDto { items = youTubeSearchItemDtos, nextPageToken = nextPageToken }; return(youTubeSearchDto); }
public MaybeResult <PlatformStreamsDto, StreamProviderError> Map( YouTubeSearchDto videoSearchResults, MaybeResult <IEnumerable <YouTubeVideoDto>, StreamProviderError> videoDetailResults, MaybeResult <IEnumerable <YouTubeChannelDto>, StreamProviderError> videoChannelResults) { return(videoDetailResults.Chain(videosResult => { return videoChannelResults.Select(channelResults => { var videoDetails = videosResult.ToDictionary(v => v.id, v => v.liveStreamingDetails); var videoChannels = channelResults.ToDictionary(c => c.id, c => c.snippet); return ToStreams(videoSearchResults, videoChannels, videoDetails); }); })); }