/// <summary>The most popular in that channel. Video's do not include related data.</summary> public async Task <ICollection <ChannelVideoListItem> > VideosInChannel(ChannelData c, DateTime publishedAfter, DateTime?publishBefore = null) { var s = YtService.Search.List("snippet"); s.ChannelId = c.Id; s.PublishedAfter = publishedAfter; s.PublishedBefore = publishBefore; s.MaxResults = 50; s.Order = SearchResource.ListRequest.OrderEnum.Date; s.Type = "video"; var vids = new List <ChannelVideoListItem>(); while (true) { var res = await GetResponse(s); vids.AddRange(res.Items.Where(v => v.Snippet.PublishedAt != null).Select(v => new ChannelVideoListItem { VideoId = v.Id.VideoId, VideoTitle = v.Snippet.Title, PublishedAt = v.Snippet.PublishedAt.ParseDate(), Updated = DateTime.UtcNow })); if (res.NextPageToken == null) { break; } s.PageToken = res.NextPageToken; } return(vids); }
public async Task <ChannelData> ChannelData(string id, bool full = false) { var channelList = YtService.Channels.List(new[] { "snippet", "statistics" }.Concat(full ? "brandingSettings" : null).NotNull().Join(",")); channelList.Id = id; var response = await GetResponse(channelList); var c = response.Items?.FirstOrDefault(); if (c == null) { return(null); } SubscriptionListResponse subRes = null; if (full) { var subs = YtService.Subscriptions.List("snippet"); subs.ChannelId = id; try { subRes = await GetResponse(subs); } catch (Exception) { Log.Debug("YtApi - getting channel {Channel} subs failed. most don't allow it so this is fine", id); } } var data = new ChannelData { Id = id, Title = c.Snippet.Title, Description = c.Snippet.Description, Country = c.Snippet.Country, Thumbnails = c.Snippet.Thumbnails, Stats = new ChannelStats { ViewCount = c.Statistics.ViewCount, SubCount = c.Statistics.SubscriberCount, Updated = DateTime.UtcNow }, FeaturedChannelIds = c.BrandingSettings?.Channel?.FeaturedChannelsUrls?.ToArray(), DefaultLanguage = c.BrandingSettings?.Channel?.DefaultLanguage, Keywords = c.BrandingSettings?.Channel?.Keywords, Subscriptions = subRes?.Items?.Select(s => new ChannelSubscription { Id = s.Snippet?.ChannelId, Title = s.Snippet?.Title }).ToArray() }; return(data); }