/// <summary> /// Gets the newest video information from the channel. /// </summary> /// <param name="channelId">Username or channel id.</param> /// <returns>Newest video information.</returns> public async Task <YtLocalFavChannelList> GetYtChannelVideoList(string channelId) { YtLocalFavChannelList videoList = new YtLocalFavChannelList(); string webResp; using (var httpClient = new HttpClient()) { webResp = await httpClient.GetStringAsync(YtApiWebQueryTemplates.GetChannelVideoListQuery(YtApiWebQueryTemplates.GetYoutubeApiKey(), channelId)); } JObject googleSearch = JObject.Parse(webResp); IList <JToken> results = googleSearch["items"].Children().ToList(); videoList.channelId = channelId; videoList.channelTitle = results[0]["snippet"]["channelTitle"].ToString(); videoList.videoTitle = results[0]["snippet"]["title"].ToString(); videoList.videoId = results[0]["id"]["videoId"].ToString(); videoList.imagePath = results[0]["snippet"]["thumbnails"]["default"]["url"].ToString(); DateTime pubTime = DateTime.Parse(results[0]["snippet"]["publishedAt"].ToString(), null, System.Globalization.DateTimeStyles.RoundtripKind); videoList.publishedAt = $"{pubTime.Date.DayOfWeek}, {pubTime.Date.Day}.{pubTime.Date.Month}.{pubTime.Date.Year} at {pubTime.TimeOfDay.ToString()}"; return(videoList); }
/// <summary> /// Gets the channel information by username or channel ID. /// </summary> /// <param name="username">Username or channel id.</param> /// <returns>Channel information (YtChannelInfo)</returns> public async Task <YtChannelInfo> GetYtChannelInfoByUser(string username) { YtChannelInfo channelInfo = new YtChannelInfo(); string webResp; using (var httpClient = new HttpClient()) { webResp = await httpClient.GetStringAsync(YtApiWebQueryTemplates.GetChannelInfoQuery(YtApiWebQueryTemplates.GetYoutubeApiKey(), username)); } JObject googleSearch = JObject.Parse(webResp); IList <JToken> results = googleSearch["items"].Children().ToList(); channelInfo.etag = results[0]["etag"].ToString(); channelInfo.kind = results[0]["kind"].ToString(); channelInfo.id = results[0]["id"].ToString(); return(channelInfo); }