Exemple #1
0
        public async void UpdateFeaturedChannels()
        {
            var service = await YoutubeItemMethodsStatic.GetServiceAsync();

            try
            {
                var methods = new YoutubeItemMethods();

                string FeaturedChannelIds = "";
                foreach (var Id in channel.BrandingSettings.Channel.FeaturedChannelsUrls)
                {
                    FeaturedChannelIds += Id + ",";
                }

                var getChannels = service.Channels.List("snippet,statistics");
                getChannels.Id = FeaturedChannelIds.Remove(FeaturedChannelIds.Length - 1, 1);
                var featuredChannelsResponse = getChannels.Execute();

                foreach (var featuredChannel in featuredChannelsResponse.Items)
                {
                    featuredChannelsTemp.Add(methods.ChannelToYoutubeChannel(featuredChannel));
                }
            }
            catch (Exception ex)
            {
                Log.Error("Featured channels failed to load");
                Log.Error(JsonConvert.SerializeObject(channel));
                Log.Error(ex.Message);
            }
        }
        public async void UpdateVideos()
        {
            List <YoutubeItemDataType> tempList = new List <YoutubeItemDataType>();

            YoutubeItemMethods methods = new YoutubeItemMethods();

            UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
            {
                ClientId     = "957928808020-pa0lopl3crh565k6jd4djaj36rm1d9i5.apps.googleusercontent.com",
                ClientSecret = "oB9U6yWFndnBqLKIRSA0nYGm"
            }, new[] { YouTubeService.Scope.Youtube }, "user", CancellationToken.None);

            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = "Youtube Viewer",
            });

            //Gets our channel which has a playlist called Watch History
            var getChannel = youtubeService.Channels.List("contentDetails");

            getChannel.Mine = true;

            var myChannel = await getChannel.ExecuteAsync();

            //Get the playlist items from the watch history playlist that we got from our channel
            var getWatchHistoryItems = youtubeService.PlaylistItems.List("snippet");

            getWatchHistoryItems.PlaylistId = myChannel.Items[0].ContentDetails.RelatedPlaylists.WatchHistory;
            getWatchHistoryItems.MaxResults = 50;

            var watchHistory = await getWatchHistoryItems.ExecuteAsync();
        }
Exemple #3
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 #4
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 #5
0
        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;
        }
Exemple #6
0
        public void UpdatePageInfo(YouTubeService service)
        {
            var methods = new YoutubeItemMethods();

            Title.Text = Constants.activeVideo.Snippet.Title;
            Views.Text = string.Format("{0:#,###0.#}", Constants.activeVideo.Statistics.ViewCount) + " Views";

            ChannelTitle.Text = channel.Snippet.Title;
            DatePosted.Text   = Constants.activeVideo.Snippet.PublishedAt.Value.ToString("MMMM d, yyyy");
            Description.Text  = Constants.activeVideo.Snippet.Description;
            DescriptionShowMore.Visibility = Visibility.Visible;
            var image      = new BitmapImage(new Uri(channel.Snippet.Thumbnails.High.Url));
            var imageBrush = new ImageBrush {
                ImageSource = image
            };

            ChannelProfileIcon.Fill = imageBrush;
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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;
        }
Exemple #9
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);
            });
        }