Ejemplo n.º 1
0
        public async void UpdateChannel()
        {
            var GetChannelInfo = (await YoutubeItemMethodsStatic.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 YoutubeItemMethodsStatic.GetServiceAsync()).Subscriptions.List("snippet");

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

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

            //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.";
            }
        }
Ejemplo n.º 2
0
        public async void UpdateData()
        {
            var service = await YoutubeItemMethodsStatic.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    = YoutubeItemMethodsStatic.ViewCountShortner(LikeCountStr, 0);
                DislikeCount.Text = YoutubeItemMethodsStatic.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.YoutubeItemMethodsStatic.ViewCountShortner(LikeCountStr + 1);
                }
                else if (video.Items[0].Rating == "dislike")
                {
                    DislikeIcon.Fill  = Application.Current.Resources["SystemControlHighlightAccentBrush"] as SolidColorBrush;
                    CurrentSelection  = "dislike";
                    DislikeCount.Text = Classes.YoutubeItemMethodsStatic.ViewCountShortner(DislikeCountStr + 1);
                }
            }
            catch { }
        }
Ejemplo n.º 3
0
        private async void SubscribeButton_Click(object sender, RoutedEventArgs e)
        {
            UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
            {
                ClientId     = "957928808020-pa0lopl3crh565k6jd4djaj36rm1d9i5.apps.googleusercontent.com",
                ClientSecret = "oB9U6yWFndnBqLKIRSA0nYGm"
            }, new[] { YouTubeService.Scope.Youtube }, "user", System.Threading.CancellationToken.None);

            // Create the service.
            var service = new YouTubeService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = "Youtube Viewer",
            });

            if (isSubscribed == true)
            {
                SubscribeButton.Content = "Subscribe " + YoutubeItemMethodsStatic.ViewCountShortner(channel.Statistics.SubscriberCount);

                var getSubscription = service.Subscriptions.List("snippet");
                getSubscription.Mine = true;
                var subscriptions = await getSubscription.ExecuteAsync();

                Subscription subscription = new Subscription();

                Constants.MainPageRef.LoadSubscriptions();
                try
                {
                    var sub = Constants.MainPageRef.subscriptionsList.Single(x => x.Id == Constants.activeChannelID);
                    try
                    {
                        var unsubscribe = service.Subscriptions.Delete(sub.SubscriptionID);
                        await unsubscribe.ExecuteAsync();

                        isSubscribed = false;
                    }
                    catch
                    {
                        //Fires if subscription could not be removed for whatever reason.
                        SubscribeButton.Content = "Subscribed " + YoutubeItemMethodsStatic.ViewCountShortner(channel.Statistics.SubscriberCount + 1);
                    }
                }
                catch
                {
                    //Fires if subscription doesn't exist.
                    SubscribeButton.Content = "Subscribe " + YoutubeItemMethodsStatic.ViewCountShortner(channel.Statistics.SubscriberCount);
                    isSubscribed            = false;
                }
            }
            else
            {
                Subscription        subscription = new Subscription();
                SubscriptionSnippet snippet      = new SubscriptionSnippet();
                ResourceId          resourceId   = new ResourceId {
                    ChannelId = Constants.activeChannelID, Kind = "youtube#channel"
                };

                snippet.ResourceId   = resourceId;
                subscription.Snippet = snippet;

                var subscribe = service.Subscriptions.Insert(subscription, "snippet");
                subscribe.Execute();

                SubscribeButton.Content = "Subscribed " + YoutubeItemMethodsStatic.ViewCountShortner(channel.Statistics.SubscriberCount + 1);

                isSubscribed = true;
            }
        }