示例#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);
            }
        }
示例#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
            });
        }
        private async void DislikeIcon_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var service = await YoutubeMethodsStatic.GetServiceAsync();

            if (CurrentSelection == "like")
            {
                var UnLikeVideo = service.Videos.Rate(Constants.activeVideoID, VideosResource.RateRequest.RatingEnum.None);
                await UnLikeVideo.ExecuteAsync();

                CurrentSelection = "none";

                LikeIcon.Fill    = new SolidColorBrush(Color.FromArgb(255, 136, 136, 136));
                DislikeIcon.Fill = new SolidColorBrush(Color.FromArgb(255, 136, 136, 136));

                LikeCount.Text    = Classes.YoutubeMethodsStatic.ViewCountShortner(LikeCountStr, 0);
                DislikeCount.Text = Classes.YoutubeMethodsStatic.ViewCountShortner(DislikeCountStr, 0);
            }
            else
            {
                var DislikeVideo = service.Videos.Rate(Constants.activeVideoID, VideosResource.RateRequest.RatingEnum.Dislike);
                await DislikeVideo.ExecuteAsync();

                CurrentSelection = "dislike";

                LikeIcon.Fill    = new SolidColorBrush(Color.FromArgb(255, 136, 136, 136));
                DislikeIcon.Fill = Application.Current.Resources["SystemControlHighlightAccentBrush"] as SolidColorBrush;

                LikeCount.Text    = Classes.YoutubeMethodsStatic.ViewCountShortner(LikeCountStr, 0);
                DislikeCount.Text = Classes.YoutubeMethodsStatic.ViewCountShortner(DislikeCountStr + 1, 0);
            }
        }
示例#4
0
        public async void StartVideo(string ID)
        {
            //Make the player cover the entire frame
            ChangePlayerSize(true);

            //Set the ID of our viewer to the new ID
            viewer.Source = ID;


            var service = await YoutubeMethodsStatic.GetServiceAsync();

            var getVideoInfo = service.Videos.List("snippet, statistics, contentDetails");

            getVideoInfo.Id = ID;
            var videoList = await getVideoInfo.ExecuteAsync();

            Constants.ActiveVideo = videoList.Items[0];

            //Channel Info
            await Task.Run(() =>
            {
                var getChannelInfo = service.Channels.List("snippet");
                getChannelInfo.Id  = Constants.ActiveVideo.Snippet.ChannelId;
                var channelInfo    = getChannelInfo.Execute();
                channel            = channelInfo.Items[0];
            });

            UpdatePageInfo(service);

            UpdateRelatedVideos(service);
        }
示例#5
0
        public async void UpdateChannel()
        {
            var GetChannelInfo = (await YoutubeMethodsStatic.GetServiceAsync()).Channels.List("snippet, brandingSettings, statistics");

            GetChannelInfo.Id = Constants.activeChannelID;
            var ChannelInfoResults = GetChannelInfo.Execute();

            channel = ChannelInfoResults.Items[0];

            //View Count
            VideoCount.Text = channel.Statistics.VideoCount + " videos";

            //Profile Image
            var ProfileImageBrush = new ImageBrush {
                ImageSource = new BitmapImage(new Uri(channel.Snippet.Thumbnails.High.Url))
            };

            ProfileImage.Fill = ProfileImageBrush;

            //Channel Name
            ChannelName.Text = channel.Snippet.Title;

            //Subscribe Button
            var CheckIfSubscribed = (await YoutubeMethodsStatic.GetServiceAsync()).Subscriptions.List("snippet");

            CheckIfSubscribed.Mine         = true;
            CheckIfSubscribed.ForChannelId = Constants.activeChannelID;
            var IsSubscribed = CheckIfSubscribed.Execute();

            if (IsSubscribed.Items.Count == 0)
            {
                SubscribeButton.Content = "Subscribe " + YoutubeMethodsStatic.ViewCountShortner(channel.Statistics.SubscriberCount);
                isSubscribed            = false;
            }
            else
            {
                SubscribeButton.Content = "Subscribed " + YoutubeMethodsStatic.ViewCountShortner(channel.Statistics.SubscriberCount);
                isSubscribed            = true;
            }


            if (channel.BrandingSettings != null)
            {
                //Banner Image
                SplashImage.Source = new BitmapImage(new Uri(channel.BrandingSettings.Image.BannerImageUrl));

                //About Page
                if (channel.BrandingSettings.Channel.Description != null)
                {
                    ChannelAboutText.Text = channel.BrandingSettings.Channel.Description;
                }
                else
                {
                    ChannelAboutText.Text = "This channel does not have a description.";
                }
            }
        }
示例#6
0
        private async void RunAuthentication()
        {
            await YoutubeMethodsStatic.GetServiceAsync();

            if (await YoutubeMethodsStatic.IsUserAuthenticated())
            {
                btnLogin.Visibility    = Visibility.Collapsed;
                btnContinue.Visibility = Visibility.Visible;
            }
        }
        private async void BtnMyChannel_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var service = await YoutubeMethodsStatic.GetServiceAsync();

            var getMyChannel = service.Channels.List("snippet");

            getMyChannel.Mine = true;
            var result = await getMyChannel.ExecuteAsync();

            Constants.activeChannelID = result.Items[0].Id;
            contentFrame.Navigate(typeof(ChannelPage));
        }
        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;
        }
        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);
        }
示例#10
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.");
                }
            }
        }
        public async void UpdateData()
        {
            var service = await YoutubeMethodsStatic.GetServiceAsync();

            //Set like and dislike counts
            try
            {
                var videoStatsRequest = service.Videos.List("statistics");
                videoStatsRequest.Id = Constants.activeVideoID;
                var videoStats = await videoStatsRequest.ExecuteAsync();

                LikeCountStr    = Convert.ToInt64(videoStats.Items[0].Statistics.LikeCount);
                DislikeCountStr = Convert.ToInt64(videoStats.Items[0].Statistics.DislikeCount);

                LikeCount.Text    = YoutubeMethodsStatic.ViewCountShortner(LikeCountStr, 0);
                DislikeCount.Text = YoutubeMethodsStatic.ViewCountShortner(DislikeCountStr, 0);

                LikesBar.Value = LikeCountStr * 100 / (LikeCountStr + DislikeCountStr + 1);

                //Find and set the rating if it already exists
                var videoRequest = service.Videos.GetRating(Constants.activeVideoID);
                var video        = await videoRequest.ExecuteAsync();

                if (video.Items[0].Rating == "like")
                {
                    LikeIcon.Fill    = Application.Current.Resources["SystemControlHighlightAccentBrush"] as SolidColorBrush;
                    CurrentSelection = "like";
                    LikeCount.Text   = Classes.YoutubeMethodsStatic.ViewCountShortner(LikeCountStr + 1);
                }
                else if (video.Items[0].Rating == "dislike")
                {
                    DislikeIcon.Fill  = Application.Current.Resources["SystemControlHighlightAccentBrush"] as SolidColorBrush;
                    CurrentSelection  = "dislike";
                    DislikeCount.Text = Classes.YoutubeMethodsStatic.ViewCountShortner(DislikeCountStr + 1);
                }
            }
            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 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);
            });
        }
示例#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 { }
            }
        }
        public async void LoadSubscriptions()
        {
            //Reset the subscriptions
            subscriptionsList.Clear();

            //Get the service
            var service = await YoutubeMethodsStatic.GetServiceAsync();

            string nextPageToken;

            //Get the subscriptions
            var tempSubscriptions = GetSubscriptions(null, service);

            if (tempSubscriptions == null)
            {
                Log.Error("Get Subscriptions returned a null object. The method \"LoadSubscriptions\" was cancelled");
                return;
            }

            foreach (Subscription sub in tempSubscriptions.Items)
            {
                SubscriptionDataType subscription = new SubscriptionDataType();
                try
                {
                    subscription = new SubscriptionDataType
                    {
                        Id             = sub.Snippet.ResourceId.ChannelId,
                        Thumbnail      = new BitmapImage(new Uri(sub.Snippet.Thumbnails.Medium.Url)),
                        Title          = sub.Snippet.Title,
                        NewVideosCount = Convert.ToString(sub.ContentDetails.NewItemCount),
                        SubscriptionID = sub.Id
                    };
                    subscriptionsList.Add(subscription);
                }
                catch (Exception ex)
                {
                    Log.Error(string.Format("Subscription failed to load. Object:", JsonConvert.SerializeObject(subscription)));
                    Log.Error(ex.Message);
                }
            }

            if (tempSubscriptions.NextPageToken != null)
            {
                nextPageToken = tempSubscriptions.NextPageToken;
                while (nextPageToken != null)
                {
                    var tempSubs = GetSubscriptions(nextPageToken, service);
                    foreach (Subscription sub in tempSubs.Items)
                    {
                        SubscriptionDataType subscription = new SubscriptionDataType();
                        try
                        {
                            subscription = new SubscriptionDataType
                            {
                                Id             = sub.Snippet.ResourceId.ChannelId,
                                Thumbnail      = new BitmapImage(new Uri(sub.Snippet.Thumbnails.Medium.Url)),
                                Title          = sub.Snippet.Title,
                                NewVideosCount = Convert.ToString(sub.ContentDetails.NewItemCount),
                                SubscriptionID = sub.Id
                            };
                            subscriptionsList.Add(subscription);
                        }
                        catch (Exception ex)
                        {
                            Log.Error(string.Format("Subscription failed to load. Object:", JsonConvert.SerializeObject(subscription)));
                            Log.Error(ex.Message);
                        }
                    }
                    nextPageToken = tempSubs.NextPageToken;
                }
            }
        }