/// <summary> /// Gets the metadata associated with the specified playlist. /// </summary> public async Task <Playlist> GetAsync(PlaylistId id) { var response = await PlaylistResponse.GetAsync(_httpClient, id); return(new Playlist( id, response.GetTitle(), response.TryGetAuthor(), response.TryGetDescription() ?? "", new Engagement( response.TryGetViewCount() ?? 0, response.TryGetLikeCount() ?? 0, response.TryGetDislikeCount() ?? 0 ))); }
/// <summary> /// Enumerates videos included in the specified playlist. /// </summary> public async IAsyncEnumerable <Video> GetVideosAsync(PlaylistId id) { var encounteredVideoIds = new HashSet <string>(); var index = 0; while (true) { var response = await PlaylistResponse.GetAsync(_httpClient, id, index); var countDelta = 0; foreach (var video in response.GetVideos()) { var videoId = video.GetId(); // Skip already encountered videos if (!encounteredVideoIds.Add(videoId)) { continue; } yield return(new Video( videoId, video.GetTitle(), video.GetAuthor(), video.GetChannelId(), video.GetUploadDate(), video.GetDescription(), video.GetDuration(), new ThumbnailSet(videoId), video.GetKeywords(), new Engagement( video.GetViewCount(), video.GetLikeCount(), video.GetDislikeCount() ) )); countDelta++; } // Videos loop around, so break when we stop seeing new videos if (countDelta <= 0) { break; } index += countDelta; } }
/// <summary> /// Gets the metadata associated with the specified playlist. /// </summary> public async Task <Playlist> GetAsync(string id) { var response = await PlaylistResponse.GetAsync(_httpClient, id); var thumbnails = response .GetVideos() .FirstOrDefault()? .GetId() .Pipe(i => new ThumbnailSet(i)); return(new Playlist( id, response.GetTitle(), response.TryGetAuthor(), response.TryGetDescription() ?? "", thumbnails)); }
/// <summary> /// Enumerates videos included in the specified playlist. /// </summary> public async IAsyncEnumerable <PlaylistVideo> GetVideosAsync(PlaylistId id) { var encounteredVideoIds = new HashSet <string>(); var continuationToken = ""; while (true) { var response = await PlaylistResponse.GetAsync(_httpClient, id, continuationToken); foreach (var video in response.GetPlaylistVideos()) { var videoId = video.GetId(); // Skip already encountered videos if (!encounteredVideoIds.Add(videoId)) { continue; } // Skip deleted videos if (string.IsNullOrEmpty(video.GetChannelId())) { continue; } yield return(new PlaylistVideo( videoId, video.GetTitle(), video.GetAuthor(), video.GetChannelId(), video.GetDescription(), video.GetDuration(), video.GetViewCount(), new ThumbnailSet(videoId) )); } continuationToken = response.TryGetContinuationToken(); if (string.IsNullOrEmpty(continuationToken)) { break; } } }
/// <summary> /// Gets the metadata associated with the specified playlist. /// </summary> public async Task <Playlist> GetAsync(PlaylistId id) { var response = await PlaylistResponse.GetAsync(_httpClient, id); var thumbnails = response .GetVideos() .FirstOrDefault()? .GetId() .Pipe(i => new ThumbnailSet(i)); return(new Playlist( id, response.GetTitle(), response.TryGetAuthor(), response.TryGetDescription() ?? "", thumbnails, new Engagement( response.TryGetViewCount() ?? 0, response.TryGetLikeCount() ?? 0, response.TryGetDislikeCount() ?? 0 ))); }
private async Task <Video> GetVideoFromMixPlaylistAsync(VideoId id) { var playlistInfo = await PlaylistResponse.GetAsync(_httpClient, "RD" + id.Value); var video = playlistInfo.GetVideos().First(x => x.GetId() == id.Value); return(new Video( id, video.GetTitle(), video.GetAuthor(), video.GetChannelId(), video.GetUploadDate(), video.GetDescription(), video.GetDuration(), new ThumbnailSet(id), video.GetKeywords(), new Engagement( video.GetViewCount(), video.GetLikeCount(), video.GetDislikeCount() ) )); }
/// <summary> /// Enumerates videos included in the specified playlist. /// </summary> public async IAsyncEnumerable <Video> GetVideosAsync(string id) { var encounteredstrings = new HashSet <string>(); var index = 0; while (true) { var response = await PlaylistResponse.GetAsync(_httpClient, id, index); var countDelta = 0; foreach (var video in response.GetVideos()) { var videoId = video.GetId(); // Skip already encountered videos if (!encounteredstrings.Add(videoId)) { continue; } //TODO yield return(null); countDelta++; } // Videos loop around, so break when we stop seeing new videos if (countDelta <= 0) { break; } index += countDelta; } }