Exemple #1
0
        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
            });
        }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
        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);
            });
        }