public static async Task <YTPlaylistsRequestResults> GetPlaylists(string channelId) { if (YouTubeAPIKey != String.Empty) { CheckYouTubAPIKey(); RegisterRequest(RequestNames.GetPlaylists); string response = await YouTubeServiceProxies.GetPlaylists(channelId, 50); if (String.IsNullOrEmpty(response)) { return(null); } YTPlaylistsRequestResults results = await YouTubeJsonParser.ParsePlaylists(response); RemoveRequest(RequestNames.GetPlaylists); return(results); } else { throw new YouTubeException() { Source = "YouTubeServices.GetPlaylists - API Key cannot be null" }; } }
public static async Task <YTPlaylistsRequestResults> ParsePlaylists(string jsonData) { return(await Task.Factory.StartNew(() => { YTPlaylistsRequestResults results; dynamic dynamicData = JsonConvert.DeserializeObject(jsonData); results = new YTPlaylistsRequestResults() { Kind = dynamicData.kind, Etag = dynamicData.etag, PageInfo = new YTPageInfoModel() { TotalResults = dynamicData.pageInfo.totalResults, ResultsPerPage = dynamicData.pageInfo.resultsPerPage }, Items = new List <YTItemModel>() }; foreach (var item in dynamicData.items) { YTItemModel itemModel = new YTItemModel() { Kind = item.kind, ETag = item.etag, Id = item.id, ContentDetails = new YTPlaylistsContentDetails() { ItemCount = item.contentDetails.itemCount } }; results.Items.Add(itemModel); } return results; })); }