80 lines
2.7 KiB
C#
80 lines
2.7 KiB
C#
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;
|
|
|
|
// 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;
|
|
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.YoutubeService;
|
|
|
|
VideosResource.ListRequest request = ytService.Videos.List("snippet,contentDetails,statistics");
|
|
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);
|
|
|
|
TimeSpan duration = XmlConvert.ToTimeSpan(item.ContentDetails.Duration);
|
|
|
|
info.Text = string.Format("{0}{1:00}:{2:00} | {3}", duration.Hours == 0? "" : duration.Hours + ":", duration.Minutes, duration.Seconds, item.Snippet.PublishedAt);
|
|
thumbnail.Source = new BitmapImage(new Uri(item.Snippet.Thumbnails.Medium.Url));
|
|
if (item.Snippet.LiveBroadcastContent == "live")
|
|
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 void Button_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
((Window.Current.Content as Frame).Content as MainPage).GoToVideo(videoId);
|
|
}
|
|
}
|
|
}
|