private async void DislikeIcon_Tapped(object sender, TappedRoutedEventArgs e) { var service = await YoutubeItemMethodsStatic.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.YoutubeItemMethodsStatic.ViewCountShortner(LikeCountStr, 0); DislikeCount.Text = Classes.YoutubeItemMethodsStatic.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.YoutubeItemMethodsStatic.ViewCountShortner(LikeCountStr, 0); DislikeCount.Text = Classes.YoutubeItemMethodsStatic.ViewCountShortner(DislikeCountStr + 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 }); }
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); } }
private async void UpdateVideo() { StopVideo(); if (!(await GetVideoData())) { return; } audioPlayer = new MediaPlayer(); videoPlayer = new MediaPlayer(); //We use this method so that we can synchronize the audio and video streams audioPlayer.Source = MediaSource.CreateFromUri(new Uri(Constants.videoInfo.Audio[0].Url)); videoPlayer.Source = MediaSource.CreateFromUri(new Uri(Constants.videoInfo.Video[0].Url)); audioPlayer.CommandManager.IsEnabled = false; videoPlayer.CommandManager.IsEnabled = false; audioPlayer.TimelineController = timelineController; videoPlayer.TimelineController = timelineController; viewer.SetMediaPlayer(videoPlayer); timelineController.Start(); //Event that allows us to set the maximum progress bar value and start updating videoPlayer.MediaOpened += VideoPlayer_MediaOpened; //Update video qualities QualityList.ItemsSource = YoutubeItemMethodsStatic.GetVideoQualityList(); }
private async void BtnMyChannel_Tapped(object sender, TappedRoutedEventArgs e) { var service = await YoutubeItemMethodsStatic.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)); }
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."; } }
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; }
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); }
private async void RunAuthentication() { try { Google.Apis.Auth.OAuth2.UserCredential credential = await Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsync(new Google.Apis.Auth.OAuth2.ClientSecrets { ClientId = "957928808020-pa0lopl3crh565k6jd4djaj36rm1d9i5.apps.googleusercontent.com", ClientSecret = "oB9U6yWFndnBqLKIRSA0nYGm" }, new[] { Google.Apis.YouTube.v3.YouTubeService.Scope.Youtube, Google.Apis.Oauth2.v2.Oauth2Service.Scope.UserinfoProfile }, "user", System.Threading.CancellationToken.None); } catch (Exception ex) { Log.Error("Authentication did not complete successfully."); Log.Error(ex.Message); } if (await YoutubeItemMethodsStatic.IsUserAuthenticated()) { btnLogin.Visibility = Visibility.Collapsed; btnContinue.Visibility = Visibility.Visible; } }
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 { } }
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 YoutubeItemMethodsStatic.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); //Store the video id /*if (localSettings.Values["History"] != null) * ((List<string>)localSettings.Values["History"]).Add(Constants.activeVideoID); * else * localSettings.Values["History"] = new List<string>() { Constants.activeVideoID };*/ }
public async void LoadSubscriptions() { //Get the service var service = await YoutubeItemMethodsStatic.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; } } }
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; } }
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); }); }
private void QualityList_ItemClick(object sender, ItemClickEventArgs e) { videoPlayer.Source = MediaSource.CreateFromUri(new Uri(YoutubeItemMethodsStatic.GetVideoQuality((VideoQuality)e.ClickedItem, false))); ButtonSettings.Flyout.Hide(); }