public async void UpdatePopularUploads() { var service = await YoutubeItemMethodsStatic.GetServiceAsync(); var methods = new YoutubeItemMethods(); ObservableCollection <YoutubeItemDataType> YoutubeItemsTemp = new ObservableCollection <YoutubeItemDataType>(); var GetChannelVideosPopular = service.Search.List("snippet"); GetChannelVideosPopular.ChannelId = Constants.activeChannelID; GetChannelVideosPopular.Order = SearchResource.ListRequest.OrderEnum.ViewCount; GetChannelVideosPopular.Type = "video"; GetChannelVideosPopular.MaxResults = 10; var ChannelVideosResultPopular = GetChannelVideosPopular.Execute(); foreach (var video in ChannelVideosResultPopular.Items) { if (video.Id.Kind == "youtube#video" && video.Id.VideoId != null && video.Snippet.LiveBroadcastContent != "live") { YoutubeItemsTemp.Add(methods.VideoToYoutubeItem(video)); } } methods.FillInViews(YoutubeItemsTemp, service); playlistsTemp.Add(new PlaylistDataType() { Title = "Popular Uploads", Items = YoutubeItemsTemp }); }
public async void AddMoreVideos() { try { if (addingVideos == false && !(nextPageToken == null || nextPageToken == "")) { addingVideos = true; } else { return; } List <YoutubeItemDataType> tempList = new List <YoutubeItemDataType>(); YoutubeItemMethods methods = new YoutubeItemMethods(); var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "AIzaSyCXOZJH2GUbdqwxZwsjTU93lFvgdnMOVD0", ApplicationName = this.GetType().ToString() }); var searchListRequest = youtubeService.Search.List("snippet"); searchListRequest.ChannelId = Constants.activeChannelID; searchListRequest.Type = "video"; searchListRequest.Order = SearchResource.ListRequest.OrderEnum.Date; searchListRequest.PageToken = nextPageToken; searchListRequest.MaxResults = 50; // Call the search.list method to retrieve results matching the specified query term. var searchListResponse = await searchListRequest.ExecuteAsync(); foreach (var video in searchListResponse.Items) { tempList.Add(methods.VideoToYoutubeItem(video)); } methods.FillInViews(tempList, youtubeService); nextPageToken = searchListResponse.NextPageToken; foreach (var video in tempList) { VideosList.Add(video); } addingVideos = false; } catch (Exception ex) { Log.Error(String.Format("An error occured while adding more videos to the channel page with the ID {0}", channel.Id)); Log.Error(ex.Message); } }
private async void SearchAddMore() { var youtubeService = await YoutubeItemMethodsStatic.GetServiceAsync(); if (addingVideos == true) { return; } addingVideos = true; var searchListRequest = youtubeService.Search.List("snippet"); searchListRequest.Q = Constants.MainPageRef.SearchBox.Text; searchListRequest.PageToken = nextPageToken; searchListRequest.MaxResults = 25; // Call the search.list method to retrieve results matching the specified query term. var searchListResponse = await searchListRequest.ExecuteAsync(); nextPageToken = searchListResponse.NextPageToken; ObservableCollection <YoutubeItemDataType> tempList = new ObservableCollection <YoutubeItemDataType>(); var methods = new YoutubeItemMethods(); foreach (var searchResult in searchListResponse.Items) { if (searchResult.Id.Kind == "youtube#video") { var data = methods.VideoToYoutubeItem(searchResult); tempList.Add(data); SearchResultsList.Add(data); } else if (searchResult.Id.Kind == "youtube#channel") { var data = methods.ChannelToYoutubeChannel(searchResult, youtubeService); SearchResultsList.Add(data); } } methods.FillInViews(tempList, youtubeService); foreach (var item in tempList) { SearchResultsList.Add(item); } addingVideos = false; }
public async void UpdateVideos() { YoutubeItemMethods methods = new YoutubeItemMethods(); var service = await YoutubeItemMethodsStatic.GetServiceAsync(); var recommendations = service.Videos.List("snippet, contentDetails"); recommendations.Chart = VideosResource.ListRequest.ChartEnum.MostPopular; recommendations.MaxResults = 25; var result = await recommendations.ExecuteAsync(); foreach (var video in result.Items) { videosList.Add(methods.VideoToYoutubeItem(video)); } methods.FillInViews(videosList, service); }
public async void UpdateRelatedVideos(YouTubeService service) { System.Collections.ObjectModel.ObservableCollection <YoutubeItemDataType> relatedVideosList = new System.Collections.ObjectModel.ObservableCollection <YoutubeItemDataType>(); await Task.Run(() => { var getRelatedVideos = service.Search.List("snippet"); getRelatedVideos.RelatedToVideoId = Constants.activeVideoID; getRelatedVideos.MaxResults = 15; getRelatedVideos.Type = "video"; var relatedVideosResponse = getRelatedVideos.Execute(); var methods = new YoutubeItemMethods(); foreach (SearchResult video in relatedVideosResponse.Items) { relatedVideosList.Add(methods.VideoToYoutubeItem(video)); } methods.FillInViews(relatedVideosList, service); }); relatedVideos.Items = relatedVideosList; }
public async void UpdateChannelSections() { var service = await YoutubeItemMethodsStatic.GetServiceAsync(); var methods = new YoutubeItemMethods(); //Get the playlists for the channel var GetChannelPlaylists = service.ChannelSections.List("snippet,contentDetails"); GetChannelPlaylists.ChannelId = Constants.activeChannelID; var ChannelPlaylistsResult = GetChannelPlaylists.Execute(); //Check if there are no playlists to process if (ChannelPlaylistsResult.Items.Count == 0) { return; } List <ObservableCollection <YoutubeItemDataType> > tempGridViews = new List <ObservableCollection <YoutubeItemDataType> >(); string tempPlaylistIds = ""; //Go through each playlist and get all its items Parallel.ForEach(ChannelPlaylistsResult.Items, playlist => { try { ObservableCollection <YoutubeItemDataType> tempPlaylistVideos = new ObservableCollection <YoutubeItemDataType>(); tempPlaylistVideos.Clear(); var GetPlaylistVideos = service.PlaylistItems.List("snippet,status"); if (playlist.ContentDetails == null || playlist.ContentDetails.Playlists[0] == null || playlist.Snippet.Type != "singlePlaylist") { return; } GetPlaylistVideos.PlaylistId = playlist.ContentDetails.Playlists[0]; GetPlaylistVideos.MaxResults = 10; var PlaylistVideosResult = GetPlaylistVideos.Execute(); foreach (var video in PlaylistVideosResult.Items) { if (video.Status.PrivacyStatus != "private") { tempPlaylistVideos.Add(methods.VideoToYoutubeItem(video)); } } methods.FillInViews(tempPlaylistVideos, service); tempGridViews.Add(tempPlaylistVideos); //Add the playlist ID for getting the title later tempPlaylistIds += playlist.ContentDetails.Playlists[0] + ","; } catch { return; } }); //Check if there are no playlists were outputed if (tempPlaylistIds == "") { return; } //Gets the title of the playlists var getPlaylistTitles = service.Playlists.List("snippet"); getPlaylistTitles.Id = tempPlaylistIds.Remove(tempPlaylistIds.Length - 1, 1); var playlistTitlesList = getPlaylistTitles.Execute(); for (int i = 0; i < tempGridViews.Count; i++) { try { playlistsTemp.Add(new PlaylistDataType() { Title = playlistTitlesList.Items[i].Snippet.Title, Items = tempGridViews[i] }); } catch { } } }
private async void UpdateHomeItems() { #region Subscriptions Log.Info("Updating the videos on the home page"); PlaylistDataType YTItemsListTemp = new PlaylistDataType() { Title = "Today" }; PlaylistDataType YTItemsListTempYesterday = new PlaylistDataType() { Title = "Yesterday" }; PlaylistDataType YTItemsListTempTwoDays = new PlaylistDataType() { Title = "Two Days Ago" }; PlaylistDataType YTItemsListTempThreeDays = new PlaylistDataType() { Title = "Three Days Ago" }; PlaylistDataType YTItemsListTempFourDays = new PlaylistDataType() { Title = "Four Days Ago" }; PlaylistDataType YTItemsListTempFiveDays = new PlaylistDataType() { Title = "Five Days Ago" }; System.Collections.Concurrent.BlockingCollection <Google.Apis.YouTube.v3.Data.SearchResult> searchResponseList = new System.Collections.Concurrent.BlockingCollection <Google.Apis.YouTube.v3.Data.SearchResult>(); var service = await YoutubeItemMethodsStatic.GetServiceAsync(); await Task.Run(() => { Parallel.ForEach(Constants.MainPageRef.subscriptionsList, subscription => { try { var tempService = service.Search.List("snippet"); tempService.ChannelId = subscription.Id; tempService.Order = SearchResource.ListRequest.OrderEnum.Date; tempService.MaxResults = 8; var response = tempService.Execute(); foreach (var video in response.Items) { searchResponseList.Add(video); } } catch (Exception ex) { Log.Error("A subscription's videos failed to load."); subscription.Thumbnail = null; Log.Error(JsonConvert.SerializeObject(subscription)); Log.Error(ex.Message); } }); }); var orderedSearchResponseList = searchResponseList.OrderByDescending(x => x.Snippet.PublishedAt).ToList(); Log.Info("Ordering videos by date and placing them in the correct list"); foreach (var video in orderedSearchResponseList) { var methods = new YoutubeItemMethods(); if (video != null && video.Id.Kind == "youtube#video" && video.Id.VideoId != null && video.Snippet.LiveBroadcastContent != "live") { try { DateTime now = DateTime.Now; var ytubeItem = methods.VideoToYoutubeItem(video); if (ytubeItem.Failed != true) { if (video.Snippet.PublishedAt > now.AddHours(-24)) { YTItemsListTemp.Items.Add(ytubeItem); } else if (video.Snippet.PublishedAt > now.AddHours(-48)) { YTItemsListTempYesterday.Items.Add(ytubeItem); } else if (video.Snippet.PublishedAt > now.AddHours(-72)) { YTItemsListTempTwoDays.Items.Add(ytubeItem); } else if (video.Snippet.PublishedAt > now.AddHours(-96)) { YTItemsListTempThreeDays.Items.Add(ytubeItem); } else if (video.Snippet.PublishedAt > now.AddHours(-120)) { YTItemsListTempFourDays.Items.Add(ytubeItem); } else if (video.Snippet.PublishedAt > now.AddHours(-144) && video.Snippet.PublishedAt <= now) { YTItemsListTempFiveDays.Items.Add(ytubeItem); } } } catch (Exception ex) { Log.Error(String.Format("A video failed to load into the home page. Json: {0}", JsonConvert.SerializeObject(video))); Log.Error(ex.Message); } } } YTItems.Add(YTItemsListTemp); YTItems.Add(YTItemsListTempYesterday); YTItems.Add(YTItemsListTempTwoDays); YTItems.Add(YTItemsListTempThreeDays); YTItems.Add(YTItemsListTempFourDays); YTItems.Add(YTItemsListTempFiveDays); #endregion LoadingRing.IsActive = false; Parallel.ForEach(YTItems, playlist => { var methodsLocal = new YoutubeItemMethods(); methodsLocal.FillInViews(playlist.Items, service); }); }