Ejemplo n.º 1
0
            public static async Task <bool> RetriveVideos()
            {
                // Show Progress Ring

                // Reset DataContext and Lists


                // Send a request to the YouTube API to search for channels
                var searchChannelRequest = youtubeService.Channels.List("contentDetails");

                searchChannelRequest.Id         = "UC70UzaroFf5GcyecHOGw-tw"; // The WinBeta Channel ID
                searchChannelRequest.MaxResults = 1;                          // Only get one result (Only can be one channel with the same channel ID)

                // API response
                var searchChannelResponse = await searchChannelRequest.ExecuteAsync();

                var channel = searchChannelResponse.Items.First(); // Choose the first (and only) item

                // Send a request to the YouTube API to search for playlists on youtube channel
                // (for now only grab upload playlist, later on will grab all playlists and let user filter)
                var playlistRequest = youtubeService.PlaylistItems.List("snippet");

                playlistRequest.PlaylistId = channel.ContentDetails.RelatedPlaylists.Uploads; // Get the uploads playlist
                playlistRequest.MaxResults = 50;                                              // Max of 50 results

                // API response
                var playlistResponse = await playlistRequest.ExecuteAsync();

                // Loop through all items in upload playlist
                foreach (var playlistItem in playlistResponse.Items)
                {
                    // Create a video object to pass into the data context
                    VideoItem video = new VideoItem()
                    {
                        Title     = playlistItem.Snippet.Title,                                           // Video Title
                        Thumbnail = ExtraFunctions.GetVideoThumbnail(playlistItem),                       // Video thumbnail <- This function gets the highest quality avaliable
                        Date      = ExtraFunctions.ConvertVideoDateTime(playlistItem.Snippet.PublishedAt) // Get the published date (formated and converted to correct time zone)
                    };

                    // Add video to data context list
                    videos.Add(video);
                }

                return(true);
            }