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


            try
            {
                var methods = new YoutubeMethods();

                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);
            }
        }
Beispiel #2
0
        public async void UpdatePopularUploads()
        {
            var service = await YoutubeMethodsStatic.GetServiceAsync();

            var methods = new YoutubeMethods();
            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();

            if (ChannelVideosResultPopular.Items.Count == 0)
            {
                return;
            }

            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
            });
        }
Beispiel #3
0
        private async void UpdateComments(CommentThreadsResource.ListRequest.OrderEnum option)
        {
            //Clear the current comments
            commentCollection.Clear();

            var methods = new YoutubeMethods();

            //Get the comments
            var service     = YoutubeMethodsStatic.GetServiceNoAuth();
            var getComments = service.CommentThreads.List("snippet,replies");

            getComments.VideoId    = Constants.activeVideoID;
            getComments.Order      = option;
            getComments.TextFormat = CommentThreadsResource.ListRequest.TextFormatEnum.PlainText;
            getComments.MaxResults = 10;
            var response = await getComments.ExecuteAsync();

            //Save the next page token
            commentNextPageToken = response.NextPageToken;

            //Add them to our collection so that they will be updated on the UI
            foreach (var commentThread in response.Items)
            {
                commentCollection.Add(new CommentContainerDataType(methods.CommentToDataType(commentThread)));
            }
        }
Beispiel #4
0
        public async void AddMoreVideos()
        {
            try
            {
                if (addingVideos == false && !(nextPageToken == null || nextPageToken == ""))
                {
                    addingVideos = true;
                }
                else
                {
                    return;
                }

                List <YoutubeItemDataType> tempList = new List <YoutubeItemDataType>();

                YoutubeMethods methods = new YoutubeMethods();

                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);
                addingVideos = false;
            }
        }
Beispiel #5
0
        private async void ViewMoreButton_Click(Windows.UI.Xaml.Documents.Hyperlink sender, Windows.UI.Xaml.Documents.HyperlinkClickEventArgs args)
        {
            if (!isExpanded)
            {
                isExpanded = !isExpanded;

                //ViewMoreButton.

                var methods = new YoutubeMethods();

                var service    = YoutubeMethodsStatic.GetServiceNoAuth();
                var getReplies = service.Comments.List("snippet");
                getReplies.ParentId   = Source.Id;
                getReplies.TextFormat = Google.Apis.YouTube.v3.CommentsResource.ListRequest.TextFormatEnum.PlainText;
                var response = await getReplies.ExecuteAsync();

                commentReplies.Clear();

                foreach (var item in response.Items)
                {
                    var comment = methods.CommentToDataType(item);

                    //If there are no likes, set it to null
                    if (comment.LikeCount == 0)
                    {
                        comment.LikeCount = null;
                    }
                    commentReplies.Add(comment);
                }
            }
            else
            {
                isExpanded = !isExpanded;

                commentReplies.Clear();

                foreach (var item in Source.Replies)
                {
                    if (commentReplies.Count > 2)
                    {
                        break;
                    }

                    //If there are no likes, set it to null
                    if (item.LikeCount == 0)
                    {
                        item.LikeCount = null;
                    }
                    commentReplies.Add(item);
                }
            }
        }
        private async void SearchAddMore()
        {
            var youtubeService = await YoutubeMethodsStatic.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 YoutubeMethods();

            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;
        }
Beispiel #7
0
        public void UpdatePageInfo(YouTubeService service)
        {
            var methods = new YoutubeMethods();

            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;
        }
        public async void UpdateVideos()
        {
            YoutubeMethods methods = new YoutubeMethods();

            var service = await YoutubeMethodsStatic.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);
        }
Beispiel #9
0
        private async void ReplyBoxSend_Click(Windows.UI.Xaml.Documents.Hyperlink sender, Windows.UI.Xaml.Documents.HyperlinkClickEventArgs args)
        {
            if (ReplyBox.Text == null || ReplyBox.Text == "")
            {
                ReplyContainer.Visibility = Visibility.Collapsed;
                return;
            }

            try
            {
                var service = await YoutubeMethodsStatic.GetServiceAsync();

                Comment comment = new Comment();
                comment.Snippet = new CommentSnippet();
                comment.Snippet.TextOriginal = ReplyBox.Text;
                comment.Snippet.ParentId     = Source.Id;

                var returnedComment = await service.Comments.Insert(comment, "snippet").ExecuteAsync();

                //Add the comment to the UI
                var methods = new YoutubeMethods();
                commentReplies.Add(methods.CommentToDataType(returnedComment));

                //Hide the reply box
                ReplyContainer.Visibility = Visibility.Collapsed;
            }
            catch (Google.GoogleApiException ex)
            {
                if (ex.Error.Code == 403)
                {
                    Constants.MainPageRef.ShowNotifcation("You have not setup a channel with your account. Please do so to post a comment.", 0);
                }
                else if (ex.Error.Code == 400)
                {
                    Constants.MainPageRef.ShowNotifcation("Your comment was too long or Youtube failed to handle the request correctly.", 5000);
                }
                else
                {
                    Constants.MainPageRef.ShowNotifcation("An error occured.");
                }
            }
        }
Beispiel #10
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 YoutubeMethods();
                foreach (SearchResult video in relatedVideosResponse.Items)
                {
                    relatedVideosList.Add(methods.VideoToYoutubeItem(video));
                }
                methods.FillInViews(relatedVideosList, service);
            });

            relatedVideos.Items = relatedVideosList;
        }
Beispiel #11
0
        private async void AddComments(CommentThreadsResource.ListRequest.OrderEnum option)
        {
            if (isAdding)
            {
                return;
            }

            isAdding = true;

            //Check if there are more comments
            if (commentNextPageToken == null || commentNextPageToken == "")
            {
                return;
            }

            var methods = new YoutubeMethods();

            //Get the comments
            var service     = YoutubeMethodsStatic.GetServiceNoAuth();
            var getComments = service.CommentThreads.List("snippet,replies");

            getComments.VideoId    = Constants.activeVideoID;
            getComments.Order      = option;
            getComments.TextFormat = CommentThreadsResource.ListRequest.TextFormatEnum.PlainText;
            getComments.PageToken  = commentNextPageToken;
            getComments.MaxResults = 15;
            var response = await getComments.ExecuteAsync();

            //Save the next page token
            commentNextPageToken = response.NextPageToken;

            //Add them to our collection so that they will be updated on the UI
            foreach (var commentThread in response.Items)
            {
                commentCollection.Add(new CommentContainerDataType(methods.CommentToDataType(commentThread)));
            }

            isAdding = false;
        }
        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 YoutubeMethodsStatic.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 YoutubeMethods();
                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 YoutubeMethods();
                methodsLocal.FillInViews(playlist.Items, service);
            });
        }
Beispiel #13
0
        public async void UpdateChannelSections()
        {
            var service = await YoutubeMethodsStatic.GetServiceAsync();

            var methods = new YoutubeMethods();

            ChannelSectionListResponse ChannelPlaylistsResult = new ChannelSectionListResponse();

            try
            {
                //Get the playlists for the channel
                var GetChannelPlaylists = service.ChannelSections.List("snippet,contentDetails");
                GetChannelPlaylists.ChannelId = Constants.activeChannelID;
                ChannelPlaylistsResult        = GetChannelPlaylists.Execute();
            }
            catch { }


            //Check if there are no playlists to process
            if (ChannelPlaylistsResult.Items == null || 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 { }
            }
        }