613 lines
25 KiB
C#
613 lines
25 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices.WindowsRuntime;
|
|
using Windows.Foundation;
|
|
using Windows.Foundation.Collections;
|
|
using Windows.UI.Xaml;
|
|
using Windows.UI.Xaml.Controls;
|
|
using Windows.UI.Xaml.Controls.Primitives;
|
|
using Windows.UI.Xaml.Data;
|
|
using Windows.UI.Xaml.Input;
|
|
using Windows.UI.Xaml.Media;
|
|
using Windows.UI.Xaml.Navigation;
|
|
using Windows.System;
|
|
|
|
using Google.Apis.YouTube.v3.Data;
|
|
using Google.Apis.YouTube.v3;
|
|
using Windows.UI.Xaml.Media.Imaging;
|
|
using System.Diagnostics;
|
|
using System.Timers;
|
|
using Windows.UI.Core;
|
|
using System.Threading;
|
|
using Windows.ApplicationModel.DataTransfer;
|
|
using Windows.Storage;
|
|
using Windows.ApplicationModel;
|
|
using Windows.Storage.Streams;
|
|
using Windows.UI.Popups;
|
|
using Windows.UI.Text;
|
|
using Windows.UI;
|
|
using FoxTube.Pages;
|
|
|
|
using MyToolkit.Multimedia;
|
|
using FoxTube.Controls;
|
|
|
|
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
|
|
|
|
namespace FoxTube
|
|
{
|
|
public enum Rating { None, Like, Dislike }
|
|
|
|
/// <summary>
|
|
/// An empty page that can be used on its own or navigated to within a Frame.
|
|
/// </summary>
|
|
public sealed partial class Video : Page
|
|
{
|
|
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
|
|
|
|
string videoId;
|
|
Google.Apis.YouTube.v3.Data.Video item;
|
|
|
|
List<string> downloads = new List<string>();
|
|
|
|
bool wide;
|
|
bool isExtended = false;
|
|
bool isAddedToLater = false;
|
|
|
|
Rating userRating = Rating.None;
|
|
|
|
public VideoPlayer player;
|
|
public CommentsPage comments;
|
|
LoadingPage LoadingScreen = new LoadingPage();
|
|
LoadingPage loadingRelated = new LoadingPage();
|
|
|
|
System.Timers.Timer streamUpdateTimer;
|
|
|
|
public Video()
|
|
{
|
|
this.InitializeComponent();
|
|
mainGrid.Children.Add(LoadingScreen);
|
|
relatedGrid.Children.Add(loadingRelated);
|
|
LoadingScreen.RefreshPage += LoadingScreen_RefreshPage;
|
|
|
|
DataTransferManager.GetForCurrentView().DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(Share);
|
|
|
|
if (Window.Current.Bounds.Width <= 1000)
|
|
{
|
|
Debug.WriteLine("Correcting layout...");
|
|
mainContent.Children.Remove(descriptionPanel);
|
|
pivot.Items.Insert(0, new PivotItem()
|
|
{
|
|
Content = descriptionPanel,
|
|
Margin = new Thickness(0, -48, 0, 0)
|
|
});
|
|
|
|
tabsPlaceholder.Children.Remove(tabs);
|
|
mainContent.Children.Add(tabs);
|
|
|
|
toDescription.Visibility = Visibility.Visible;
|
|
grid.ColumnDefinitions[1].Width = new GridLength(0);
|
|
|
|
pivot.SelectedIndex = 0;
|
|
pivot_SelectionChanged(this, null);
|
|
}
|
|
}
|
|
|
|
public async void Initialize(string id)
|
|
{
|
|
try
|
|
{
|
|
grid.Visibility = Visibility.Collapsed;
|
|
LoadingScreen.Refresh();
|
|
LoadingScreen.Visibility = Visibility.Visible;
|
|
videoId = id;
|
|
VideosResource.ListRequest request = SecretsVault.NoAuthService.Videos.List("snippet,contentDetails,statistics,status,liveStreamingDetails");
|
|
request.Id = id;
|
|
|
|
VideoListResponse response = await request.ExecuteAsync();
|
|
item = response.Items[0];
|
|
|
|
if (item.Snippet.LiveBroadcastContent == "live")
|
|
{
|
|
views.Text = string.Format("{0:0,0} viewers", item.LiveStreamingDetails.ConcurrentViewers);
|
|
streamUpdateTimer = new System.Timers.Timer(10000);
|
|
streamUpdateTimer.Elapsed += StreamUpdateTimer_Elapsed;
|
|
toComments.Visibility = Visibility.Collapsed;
|
|
pivot.Items.RemoveAt(pivot.Items.Count - 1);
|
|
//(toComments.Content as TextBlock).Text = "Chat";
|
|
}
|
|
else
|
|
{
|
|
views.Text = string.Format("{0:0,0} views", item.Statistics.ViewCount);
|
|
comments = new CommentsPage();
|
|
commentsPlaceholder.Content = null;
|
|
commentsPlaceholder.Content = comments;
|
|
comments.Initialize(item);
|
|
}
|
|
|
|
VideoCategoriesResource.ListRequest categoryRequest = SecretsVault.NoAuthService.VideoCategories.List("snippet");
|
|
categoryRequest.Id = item.Snippet.CategoryId;
|
|
VideoCategoryListResponse categoryResponse = await categoryRequest.ExecuteAsync();
|
|
VideoCategory cat = categoryResponse.Items[0];
|
|
category.Text = cat.Snippet.Title;
|
|
|
|
if (item.Status.License == "youtube")
|
|
license.Text = "Standard YouTube License";
|
|
else license.Text = "Creative Commons Attribution license (reuse allowed)";
|
|
|
|
publishedAt.Text = item.Snippet.PublishedAt.Value.ToString("d, MMMM, yyyy");
|
|
title.Text = item.Snippet.Title;
|
|
dislikes.Text = item.Statistics.DislikeCount.ToString();
|
|
likes.Text = item.Statistics.LikeCount.ToString();
|
|
rating.Value = (double)item.Statistics.DislikeCount / (double)(item.Statistics.DislikeCount + item.Statistics.LikeCount) * 100;
|
|
Methods.FormatText(ref description, item.Snippet.Description);
|
|
|
|
ChannelsResource.ListRequest request1 = SecretsVault.NoAuthService.Channels.List("snippet,contentDetails,statistics");
|
|
request1.Id = item.Snippet.ChannelId;
|
|
|
|
ChannelListResponse response1 = await request1.ExecuteAsync();
|
|
var item1 = response1.Items[0];
|
|
|
|
channelAvatar.ProfilePicture = new BitmapImage(new Uri(item1.Snippet.Thumbnails.Medium.Url));
|
|
channelName.Text = item.Snippet.ChannelTitle;
|
|
subscribers.Text = string.Format("{0:0,0} subscribers", item1.Statistics.SubscriberCount);
|
|
|
|
|
|
if(SecretsVault.IsAuthorized)
|
|
{
|
|
VideoGetRatingResponse ratingResponse = await SecretsVault.Service.Videos.GetRating(id).ExecuteAsync();
|
|
if (ratingResponse.Items[0].Rating == "like")
|
|
{
|
|
userRating = Rating.Like;
|
|
like.Foreground = new SolidColorBrush(Colors.Green);
|
|
}
|
|
else if (ratingResponse.Items[0].Rating == "dislike")
|
|
{
|
|
userRating = Rating.Dislike;
|
|
dislike.Foreground = new SolidColorBrush(Colors.Red);
|
|
}
|
|
|
|
/*addLater.Visibility = Visibility.Visible;
|
|
addToPlaylist.Visibility = Visibility.Visible;
|
|
|
|
if (SecretsVault.WatchLater.Contains(item.Id))
|
|
{
|
|
isAddedToLater = true;
|
|
addLater.IsChecked = true;
|
|
}*/
|
|
}
|
|
|
|
player = new VideoPlayer(item, item1.Snippet.Thumbnails.Medium.Url);
|
|
player.SetFullSize += Player_SetFullSize;
|
|
|
|
playerPlaceholder.Children.Add(player);
|
|
|
|
LoadDownloads();
|
|
|
|
Thread.Sleep(1000);
|
|
grid.Visibility = Visibility.Visible;
|
|
LoadingScreen.Visibility = Visibility.Collapsed;
|
|
|
|
LoadRelatedVideos();
|
|
|
|
/*if (SecretsVault.IsAuthorized && SecretsVault.UserHistory[0] != item.Id)
|
|
{
|
|
await SecretsVault.Service.PlaylistItems.Insert(new PlaylistItem()
|
|
{
|
|
Snippet = new PlaylistItemSnippet()
|
|
{
|
|
ResourceId = new ResourceId()
|
|
{
|
|
Kind = "youtube#video",
|
|
VideoId = item.Id
|
|
},
|
|
PlaylistId = SecretsVault.UserChannel.ContentDetails.RelatedPlaylists.WatchHistory
|
|
}
|
|
}, "snippet").ExecuteAsync();
|
|
SecretsVault.UserHistory.Insert(0, item.Id);
|
|
}*/
|
|
}
|
|
catch
|
|
{
|
|
LoadingScreen.Error();
|
|
}
|
|
}
|
|
|
|
async void LoadDownloads()
|
|
{
|
|
Debug.WriteLine("Loading download options...");
|
|
downloadSelector.Items.Clear();
|
|
|
|
YouTubeUri[] uris = await YouTube.GetUrisAsync(item.Id);
|
|
if (uris.Length > 0)
|
|
foreach (YouTubeUri u in uris)
|
|
{
|
|
if (u.HasAudio && u.HasVideo)
|
|
{
|
|
downloads.Add(u.Uri.AbsoluteUri);
|
|
MenuFlyoutItem menuItem = new MenuFlyoutItem()
|
|
{
|
|
Text = Methods.QualityToString(u.VideoQuality)
|
|
};
|
|
menuItem.Click += downloadItemSelected;
|
|
downloadSelector.Items.Add(menuItem);
|
|
}
|
|
else if (u.HasAudio)
|
|
{
|
|
downloads.Add(u.Uri.AbsoluteUri);
|
|
MenuFlyoutItem menuItem = new MenuFlyoutItem()
|
|
{
|
|
Text = Methods.QualityToString(u.AudioQuality)
|
|
};
|
|
menuItem.Click += downloadItemSelected;
|
|
downloadSelector.Items.Add(menuItem);
|
|
}
|
|
}
|
|
else
|
|
download.Visibility = Visibility.Collapsed;
|
|
Debug.WriteLine("Done");
|
|
}
|
|
|
|
private void downloadItemSelected(object sender, RoutedEventArgs e)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
async void LoadRelatedVideos()
|
|
{
|
|
loadingRelated.Refresh();
|
|
loadingRelated.Visibility = Visibility.Visible;
|
|
|
|
SearchResource.ListRequest request = SecretsVault.IsAuthorized? SecretsVault.Service.Search.List("snippet") : SecretsVault.NoAuthService.Search.List("snippet");
|
|
request.RelatedToVideoId = videoId;
|
|
request.SafeSearch = (SearchResource.ListRequest.SafeSearchEnum)(int)settings.Values["safeSearch"];
|
|
request.MaxResults = 20;
|
|
request.Type = "video";
|
|
|
|
SearchListResponse response = await request.ExecuteAsync();
|
|
|
|
foreach (SearchResult video in response.Items)
|
|
relatedVideos.Children.Add(new VideoCard(video.Id.VideoId));
|
|
|
|
loadingRelated.Visibility = Visibility.Collapsed;
|
|
}
|
|
|
|
private async void StreamUpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
|
|
{
|
|
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, UpdateStreamDetails);
|
|
}
|
|
|
|
async void UpdateStreamDetails()
|
|
{
|
|
VideosResource.ListRequest request = SecretsVault.NoAuthService.Videos.List("statistics,liveStreamingDetails");
|
|
request.Id = videoId;
|
|
|
|
VideoListResponse response = await request.ExecuteAsync();
|
|
var itemTemp = response.Items[0];
|
|
|
|
if (itemTemp.Snippet.LiveBroadcastContent == "live")
|
|
{
|
|
views.Text = itemTemp.LiveStreamingDetails.ConcurrentViewers + " viewers";
|
|
|
|
dislikes.Text = itemTemp.Statistics.DislikeCount.ToString();
|
|
likes.Text = itemTemp.Statistics.LikeCount.ToString();
|
|
rating.Value = (double)itemTemp.Statistics.DislikeCount / (double)(itemTemp.Statistics.DislikeCount + itemTemp.Statistics.LikeCount) * 100;
|
|
}
|
|
else streamUpdateTimer.Stop();
|
|
}
|
|
|
|
private void Player_SetFullSize(object sender, EventArgs e)
|
|
{
|
|
isExtended = !isExtended;
|
|
if(isExtended)
|
|
{
|
|
grid.ColumnDefinitions[1].Width = new GridLength(0);
|
|
|
|
tabs.Visibility = Visibility.Collapsed;
|
|
descriptionPanel.Visibility = Visibility.Collapsed;
|
|
commandbar.Visibility = Visibility.Collapsed;
|
|
|
|
mainScroll.Margin = new Thickness(0);
|
|
mainScroll.ChangeView(0, 0, null);
|
|
mainScroll.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
|
|
mainScroll.VerticalScrollMode = ScrollMode.Disabled;
|
|
}
|
|
else
|
|
{
|
|
tabs.Visibility = Visibility.Visible;
|
|
descriptionPanel.Visibility = Visibility.Visible;
|
|
commandbar.Visibility = Visibility.Visible;
|
|
|
|
mainScroll.Margin = new Thickness(0,0,0,50);
|
|
mainScroll.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
|
|
mainScroll.VerticalScrollMode = ScrollMode.Auto;
|
|
|
|
if (wide)
|
|
grid.ColumnDefinitions[1].Width = new GridLength(400);
|
|
}
|
|
}
|
|
|
|
private void gotoChannel_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
((Window.Current.Content as Frame).Content as MainPage).GoToChannel(item.Snippet.ChannelId);
|
|
}
|
|
|
|
private async void openBrowser_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
player.Pause();
|
|
string timecode = player.elapsed.TotalSeconds > 10 ?
|
|
"&t=" + (int)player.elapsed.TotalSeconds + "s" : string.Empty;
|
|
|
|
await Launcher.LaunchUriAsync(new Uri(string.Format("https://www.youtube.com/watch?v={0}{1}", videoId, timecode)));
|
|
}
|
|
|
|
private void refresh_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
playerPlaceholder.Children.Clear();
|
|
player = null;
|
|
|
|
Initialize(videoId);
|
|
}
|
|
|
|
private void LoadingScreen_RefreshPage(object sender, RoutedEventArgs e)
|
|
{
|
|
refresh_Click(this, null);
|
|
}
|
|
|
|
private void grid_SizeChanged(object sender, SizeChangedEventArgs e)
|
|
{
|
|
if (e.NewSize.Width > 1000)
|
|
wide = true;
|
|
else
|
|
wide = false;
|
|
|
|
if (e.NewSize.Width > 1000 && e.PreviousSize.Width <= 1000 && !isExtended)
|
|
{
|
|
if (mainContent.Children.Contains(tabs))
|
|
{
|
|
mainContent.Children.Remove(tabs);
|
|
tabsPlaceholder.Children.Add(tabs);
|
|
|
|
(pivot.Items[0] as PivotItem).Content = null;
|
|
pivot.Items.RemoveAt(0);
|
|
mainContent.Children.Add(descriptionPanel);
|
|
}
|
|
|
|
toDescription.Visibility = Visibility.Collapsed;
|
|
grid.ColumnDefinitions[1].Width = new GridLength(400);
|
|
}
|
|
else if (e.NewSize.Width <= 1000 & e.PreviousSize.Width > 1000)
|
|
{
|
|
if (mainContent.Children.Contains(descriptionPanel))
|
|
{
|
|
mainContent.Children.Remove(descriptionPanel);
|
|
pivot.Items.Insert(0, new PivotItem()
|
|
{
|
|
Content = descriptionPanel,
|
|
Margin = new Thickness(0, -48, 0, 0)
|
|
});
|
|
|
|
tabsPlaceholder.Children.Remove(tabs);
|
|
mainContent.Children.Add(tabs);
|
|
}
|
|
|
|
toDescription.Visibility = Visibility.Visible;
|
|
grid.ColumnDefinitions[1].Width = new GridLength(0);
|
|
}
|
|
|
|
pivot.SelectedIndex = 0;
|
|
pivot_SelectionChanged(this, null);
|
|
}
|
|
|
|
private void toDescription_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
pivot.SelectedIndex = 0;
|
|
}
|
|
|
|
private void toPlaylist_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
pivot.SelectedIndex = pivot.Items.Count - 3;
|
|
}
|
|
|
|
private void toComments_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
pivot.SelectedIndex = pivot.Items.Count - 1;
|
|
}
|
|
|
|
private void toSuggestions_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
pivot.SelectedIndex = pivot.Items.Count - 2;
|
|
}
|
|
|
|
private async void Share(DataTransferManager sender, DataRequestedEventArgs args)
|
|
{
|
|
player.Pause();
|
|
DataRequest request = args.Request;
|
|
request.Data.Properties.Title = item.Snippet.Title;
|
|
request.Data.Properties.Description = "Sharing a video";
|
|
|
|
// Handle errors
|
|
//request.FailWithDisplayText("Something unexpected could happen.");
|
|
|
|
// Plain text
|
|
request.Data.SetText(item.Snippet.Title + "\n" + "#YouTube #FoxTube #SharedWithFoxTube");
|
|
|
|
// Uniform Resource Identifiers (URIs)
|
|
request.Data.SetWebLink(new Uri(string.Format("https://www.youtube.com/watch?v={0}", videoId)));
|
|
|
|
// HTML
|
|
//request.Data.SetHtmlFormat("<b>Bold Text</b>");
|
|
|
|
// Because we are making async calls in the DataRequested event handler,
|
|
// we need to get the deferral first.
|
|
DataRequestDeferral deferral = request.GetDeferral();
|
|
|
|
// Make sure we always call Complete on the deferral.
|
|
try
|
|
{
|
|
StorageFile thumbnailFile = await Package.Current.InstalledLocation.GetFileAsync(item.Snippet.Thumbnails.Medium.Url);
|
|
request.Data.Properties.Thumbnail = RandomAccessStreamReference.CreateFromFile(thumbnailFile);
|
|
StorageFile imageFile = await Package.Current.InstalledLocation.GetFileAsync(item.Snippet.Thumbnails.Medium.Url);
|
|
|
|
// Bitmaps
|
|
request.Data.SetBitmap(RandomAccessStreamReference.CreateFromFile(imageFile));
|
|
}
|
|
finally
|
|
{
|
|
deferral.Complete();
|
|
}
|
|
}
|
|
|
|
private void share_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
DataTransferManager.ShowShareUI();
|
|
}
|
|
|
|
private void pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
toDescription.FontWeight = FontWeights.Normal;
|
|
toPlaylist.FontWeight = FontWeights.Normal;
|
|
toSuggestions.FontWeight = FontWeights.Normal;
|
|
toComments.FontWeight = FontWeights.Normal;
|
|
|
|
if (pivot.SelectedIndex == 0)
|
|
{
|
|
if (toDescription.Visibility != Visibility.Collapsed)
|
|
toDescription.FontWeight = FontWeights.Bold;
|
|
else if (toPlaylist.Visibility != Visibility.Collapsed)
|
|
toPlaylist.FontWeight = FontWeights.Bold;
|
|
else
|
|
toSuggestions.FontWeight = FontWeights.Bold;
|
|
}
|
|
else if (pivot.SelectedIndex == 1)
|
|
{
|
|
if (toDescription.Visibility == Visibility.Collapsed)
|
|
{
|
|
if (toPlaylist.Visibility == Visibility.Collapsed)
|
|
toComments.FontWeight = FontWeights.Bold;
|
|
else
|
|
toSuggestions.FontWeight = FontWeights.Bold;
|
|
}
|
|
else
|
|
{
|
|
if (toPlaylist.Visibility != Visibility.Collapsed)
|
|
toPlaylist.FontWeight = FontWeights.Bold;
|
|
else
|
|
toSuggestions.FontWeight = FontWeights.Bold;
|
|
}
|
|
|
|
}
|
|
else if (pivot.SelectedIndex == 2)
|
|
{
|
|
if(toDescription.Visibility != Visibility.Collapsed && toPlaylist.Visibility != Visibility.Collapsed)
|
|
toSuggestions.FontWeight = FontWeights.Bold;
|
|
else if (toDescription.Visibility != Visibility.Collapsed || toPlaylist.Visibility != Visibility.Collapsed)
|
|
toComments.FontWeight = FontWeights.Bold;
|
|
}
|
|
else if (pivot.SelectedIndex == 3)
|
|
toComments.FontWeight = FontWeights.Bold;
|
|
}
|
|
|
|
private async void dislike_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (SecretsVault.IsAuthorized)
|
|
switch (userRating)
|
|
{
|
|
case Rating.Like:
|
|
like.Foreground = new SolidColorBrush(Colors.Gray);
|
|
likes.Text = (Convert.ToInt32(likes.Text) - 1).ToString();
|
|
|
|
dislike.Foreground = new SolidColorBrush(Colors.Red);
|
|
dislikes.Text = (Convert.ToInt32(dislikes.Text) + 1).ToString();
|
|
rating.Value = (int)((item.Statistics.LikeCount - 1) / (item.Statistics.DislikeCount + item.Statistics.LikeCount) * 100);
|
|
await SecretsVault.Service.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.Dislike).ExecuteAsync();
|
|
|
|
userRating = Rating.Dislike;
|
|
break;
|
|
|
|
case Rating.None:
|
|
dislike.Foreground = new SolidColorBrush(Colors.Red);
|
|
dislikes.Text = (Convert.ToInt32(dislikes.Text) + 1).ToString();
|
|
rating.Value = (int)((item.Statistics.LikeCount) / (item.Statistics.DislikeCount + item.Statistics.LikeCount + 1) * 100);
|
|
await SecretsVault.Service.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.Dislike).ExecuteAsync();
|
|
|
|
userRating = Rating.Dislike;
|
|
break;
|
|
|
|
case Rating.Dislike:
|
|
dislike.Foreground = new SolidColorBrush(Colors.Gray);
|
|
dislikes.Text = (Convert.ToInt32(dislikes.Text) - 1).ToString();
|
|
rating.Value = (int)((item.Statistics.LikeCount) / (item.Statistics.DislikeCount + item.Statistics.LikeCount - 1) * 100);
|
|
await SecretsVault.Service.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.None).ExecuteAsync();
|
|
break;
|
|
}
|
|
}
|
|
|
|
private async void like_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if(SecretsVault.IsAuthorized)
|
|
switch (userRating)
|
|
{
|
|
case Rating.Dislike:
|
|
dislike.Foreground = new SolidColorBrush(Colors.Gray);
|
|
dislikes.Text = (Convert.ToInt32(dislikes.Text) - 1).ToString();
|
|
|
|
like.Foreground = new SolidColorBrush(Colors.Green);
|
|
likes.Text = (Convert.ToInt32(likes.Text) + 1).ToString();
|
|
rating.Value = (int)((item.Statistics.LikeCount + 1) / (item.Statistics.DislikeCount + item.Statistics.LikeCount) * 100);
|
|
await SecretsVault.Service.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.Like).ExecuteAsync();
|
|
|
|
userRating = Rating.Like;
|
|
break;
|
|
|
|
case Rating.None:
|
|
like.Foreground = new SolidColorBrush(Colors.Green);
|
|
likes.Text = (Convert.ToInt32(likes.Text) + 1).ToString();
|
|
rating.Value = (int)((item.Statistics.LikeCount + 1) / (item.Statistics.DislikeCount + item.Statistics.LikeCount + 1) * 100);
|
|
await SecretsVault.Service.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.Like).ExecuteAsync();
|
|
|
|
userRating = Rating.Like;
|
|
break;
|
|
|
|
case Rating.Like:
|
|
like.Foreground = new SolidColorBrush(Colors.Gray);
|
|
likes.Text = (Convert.ToInt32(likes.Text) - 1).ToString();
|
|
rating.Value = (int)((item.Statistics.LikeCount - 1) / (item.Statistics.DislikeCount + item.Statistics.LikeCount - 1) * 100);
|
|
await SecretsVault.Service.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.None).ExecuteAsync();
|
|
break;
|
|
}
|
|
}
|
|
|
|
private async void addLater_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
isAddedToLater = !isAddedToLater;
|
|
if(isAddedToLater)
|
|
{
|
|
PlaylistItem pi = await SecretsVault.Service.PlaylistItems.Insert(new PlaylistItem()
|
|
{
|
|
Snippet = new PlaylistItemSnippet()
|
|
{
|
|
ResourceId = new ResourceId()
|
|
{
|
|
Kind = "youtube#video",
|
|
VideoId = item.Id
|
|
},
|
|
PlaylistId = SecretsVault.UserChannel.ContentDetails.RelatedPlaylists.WatchLater
|
|
}
|
|
}, "snippet").ExecuteAsync();
|
|
SecretsVault.WatchLater.Insert(0, pi);
|
|
}
|
|
else
|
|
{
|
|
//await SecretsVault.Service.PlaylistItems.Delete(SecretsVault.WatchLater[])
|
|
}
|
|
}
|
|
|
|
private void addToPlaylist_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|