113 lines
4.8 KiB
C#
113 lines
4.8 KiB
C#
using System;
|
|
using Windows.UI.Xaml;
|
|
using Windows.UI.Xaml.Controls;
|
|
using Google.Apis.YouTube.v3;
|
|
using Google.Apis.YouTube.v3.Data;
|
|
using Windows.UI.Xaml.Media.Imaging;
|
|
using System.Xml;
|
|
using Windows.System;
|
|
using Windows.UI.Popups;
|
|
|
|
namespace FoxTube.Controls
|
|
{
|
|
public sealed partial class VideoCard : UserControl
|
|
{
|
|
public string playlistId;
|
|
public string videoId;
|
|
Video item;
|
|
|
|
bool embed = false;
|
|
public VideoCard(string id, string playlist = null)
|
|
{
|
|
this.InitializeComponent();
|
|
Initialize(id, playlist);
|
|
}
|
|
|
|
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
|
|
{
|
|
Height = e.NewSize.Width * 0.75;
|
|
}
|
|
|
|
public async void Initialize(string id, string playlist = null)
|
|
{
|
|
VideosResource.ListRequest request = SecretsVault.Service.Videos.List("snippet,contentDetails,statistics,liveStreamingDetails");
|
|
request.Id = id;
|
|
VideoListResponse response = await request.ExecuteAsync();
|
|
|
|
item = response.Items[0];
|
|
videoId = id;
|
|
playlistId = playlist;
|
|
|
|
title.Text = item.Snippet.Title;
|
|
channelName.Text = item.Snippet.ChannelTitle;
|
|
if (item.Snippet.LiveBroadcastContent == "live")
|
|
{
|
|
views.Text = $"{item.LiveStreamingDetails.ConcurrentViewers:0,0} viewers";
|
|
if (item.LiveStreamingDetails.ScheduledStartTime.HasValue && item.LiveStreamingDetails.ScheduledEndTime.HasValue)
|
|
info.Text = $"{item.LiveStreamingDetails.ScheduledEndTime - item.LiveStreamingDetails.ScheduledStartTime} | {Methods.GetAgo(item.LiveStreamingDetails.ActualStartTime.Value)}";
|
|
else
|
|
info.Text = item.LiveStreamingDetails.ActualStartTime.Value.ToString();
|
|
liveTag.Visibility = Visibility.Visible;
|
|
}
|
|
else if(item.Snippet.LiveBroadcastContent == "upcoming")
|
|
{
|
|
views.Text = "";
|
|
if (item.LiveStreamingDetails.ScheduledStartTime.HasValue && item.LiveStreamingDetails.ScheduledEndTime.HasValue)
|
|
info.Text = $"{item.LiveStreamingDetails.ScheduledEndTime - item.LiveStreamingDetails.ScheduledStartTime} | {item.LiveStreamingDetails.ScheduledStartTime}";
|
|
else
|
|
info.Text = $"{Methods.GetAgo(item.Snippet.PublishedAt.Value)}";
|
|
liveTag.Visibility = Visibility.Visible;
|
|
|
|
if (item.LiveStreamingDetails.ScheduledStartTime.HasValue && (item.LiveStreamingDetails.ScheduledStartTime - DateTime.Now).Value.TotalMilliseconds > 0)
|
|
liveContent.Text = $"Goes live in {item.LiveStreamingDetails.ScheduledStartTime}";
|
|
else liveContent.Text = "Upcoming";
|
|
}
|
|
else
|
|
{
|
|
views.Text = $"{item.Statistics.ViewCount:0,0} views";
|
|
string dur = string.Empty;
|
|
try { XmlConvert.ToTimeSpan(item.ContentDetails.Duration); }
|
|
catch { }
|
|
info.Text = $"{dur} | {Methods.GetAgo(item.Snippet.PublishedAt.Value)}";
|
|
embed = false;
|
|
}
|
|
|
|
var request1 = SecretsVault.Service.Channels.List("snippet");
|
|
request1.Id = item.Snippet.ChannelId;
|
|
ChannelListResponse response1 = await request1.ExecuteAsync();
|
|
|
|
try
|
|
{
|
|
avatar.ProfilePicture = new BitmapImage(new Uri(response1.Items[0].Snippet.Thumbnails.Medium.Url));
|
|
thumbnail.Source = new BitmapImage(new Uri((item.Snippet.Thumbnails.Maxres ?? item.Snippet.Thumbnails.Medium).Url));
|
|
}
|
|
catch { }
|
|
|
|
/*if(SecretsVault.UserHistory.Exists(x => x.Id == videoId))
|
|
{
|
|
watched.Visibility = Visibility.Visible;
|
|
leftOn.Value = SecretsVault.UserHistory.Find(x => x.Id == videoId).LeftOn;
|
|
}*/
|
|
}
|
|
|
|
public async void Button_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (embed)
|
|
{
|
|
MessageDialog dialog = new MessageDialog("Unfortunately, at this stage of application development we don't support live steams. This issue will be fixed in the next update. Sorry. Would you like us to open this stream in browser?", "Open in browser");
|
|
|
|
dialog.Commands.Add(new UICommand("Yes", async (command) =>
|
|
{
|
|
await Launcher.LaunchUriAsync(new Uri($"https://www.youtube.com/watch?v={videoId}"));
|
|
}));
|
|
dialog.Commands.Add(new UICommand("No"));
|
|
dialog.DefaultCommandIndex = 0;
|
|
dialog.CancelCommandIndex = 1;
|
|
await dialog.ShowAsync();
|
|
}
|
|
else
|
|
Methods.MainPage.GoToVideo(videoId, playlistId);
|
|
}
|
|
}
|
|
}
|