Development 1.1
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
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 Google.Apis.Services;
|
||||
using Google.Apis.YouTube.v3;
|
||||
using Google.Apis.YouTube.v3.Data;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
using System.Xml;
|
||||
using Windows.System;
|
||||
|
||||
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
|
||||
|
||||
namespace FoxTube
|
||||
{
|
||||
public sealed partial class VideoCard : UserControl
|
||||
{
|
||||
public string videoId;
|
||||
Google.Apis.YouTube.v3.Data.Video item;
|
||||
|
||||
bool embed = false;
|
||||
public VideoCard(string id)
|
||||
{
|
||||
this.InitializeComponent();
|
||||
Initialize(id);
|
||||
}
|
||||
|
||||
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
Height = e.NewSize.Width * 0.75;
|
||||
}
|
||||
|
||||
public async void Initialize(string id)
|
||||
{
|
||||
YouTubeService ytService = SecretsVault.NoAuthService;
|
||||
|
||||
VideosResource.ListRequest request = ytService.Videos.List("snippet,contentDetails,statistics,liveStreamingDetails");
|
||||
request.Id = id;
|
||||
VideoListResponse response = await request.ExecuteAsync();
|
||||
|
||||
item = response.Items[0];
|
||||
|
||||
videoId = id;
|
||||
|
||||
title.Text = item.Snippet.Title;
|
||||
views.Text = string.Format("{0} views", item.Statistics.ViewCount);
|
||||
|
||||
string duration;
|
||||
if (item.ContentDetails.Duration != null || item.ContentDetails.Duration != "")
|
||||
{
|
||||
TimeSpan ts = XmlConvert.ToTimeSpan(item.ContentDetails.Duration);
|
||||
duration = string.Format("{0}{1:00}:{2:00} | ", ts.Hours == 0 ? "" : ts.Hours + ":", ts.Minutes, ts.Seconds);
|
||||
}
|
||||
else duration = string.Empty;
|
||||
|
||||
info.Text = string.Format("{0}{1} | {2}", duration, Methods.GetAgo(item.Snippet.PublishedAt.Value), (item.LiveStreamingDetails != null && item.LiveStreamingDetails.ConcurrentViewers.HasValue) ? item.LiveStreamingDetails.ConcurrentViewers + " viewers" : item.Statistics.ViewCount + " views");
|
||||
thumbnail.Source = new BitmapImage(new Uri(item.Snippet.Thumbnails.Medium.Url));
|
||||
if (item.Snippet.LiveBroadcastContent == "live")
|
||||
{
|
||||
embed = true;
|
||||
liveTag.Visibility = Visibility.Visible;
|
||||
}
|
||||
else if (item.Snippet.LiveBroadcastContent == "upcoming")
|
||||
{
|
||||
embed = true;
|
||||
TimeSpan span;
|
||||
if (item.LiveStreamingDetails.ScheduledStartTime != null && (item.LiveStreamingDetails.ScheduledStartTime - DateTime.Now).Value.TotalMilliseconds > 0)
|
||||
{
|
||||
span = (TimeSpan)(item.LiveStreamingDetails.ScheduledStartTime - DateTime.Now);
|
||||
liveContent.Text = "Goes live in " + string.Format("{0}{1:00}:{2:00}:{3:00}", span.Days != 0 ? span.Days + ":" : "", span.Hours, span.Minutes, span.Seconds);
|
||||
}
|
||||
else
|
||||
liveContent.Text = "Upcoming";
|
||||
liveTag.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
var request1 = ytService.Channels.List("snippet,contentDetails,statistics");
|
||||
request1.Id = item.Snippet.ChannelId;
|
||||
ChannelListResponse response1 = await request1.ExecuteAsync();
|
||||
|
||||
var item1 = response1.Items[0];
|
||||
|
||||
avatar.ProfilePicture = new BitmapImage(new Uri(item1.Snippet.Thumbnails.Medium.Url));
|
||||
channelName.Text = item1.Snippet.Title;
|
||||
}
|
||||
|
||||
private async void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (embed)
|
||||
await Launcher.LaunchUriAsync(new Uri(string.Format("https://www.youtube.com/watch?v={0}", videoId)));
|
||||
else
|
||||
Methods.MainPage.GoToVideo(videoId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user