3bca3a30be
Merged to YouTubeExplode instead of MyToolkit
113 lines
3.7 KiB
C#
113 lines
3.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using Windows.UI.Xaml;
|
|
using Windows.UI.Xaml.Controls;
|
|
using System.Net;
|
|
using Windows.UI.Xaml.Media.Imaging;
|
|
using Windows.System;
|
|
using FoxTube.Classes;
|
|
using YoutubeExplode.Models.MediaStreams;
|
|
|
|
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
|
|
|
|
namespace FoxTube.Controls
|
|
{
|
|
public sealed partial class DownloadItem : UserControl
|
|
{
|
|
public DownloadItemContainer Container { get; private set; }
|
|
public bool InProgress { get; set; } = false;
|
|
|
|
public DownloadItem(string url)
|
|
{
|
|
this.InitializeComponent();
|
|
Download(url);
|
|
}
|
|
|
|
public DownloadItem(DownloadItemContainer container)
|
|
{
|
|
this.InitializeComponent();
|
|
|
|
Container = container;
|
|
if (!File.Exists(container.Path.AbsolutePath))
|
|
throw new FileNotFoundException();
|
|
|
|
title.Text = Container.Title;
|
|
thumbnail.Source = new BitmapImage(Container.Thumbnail);
|
|
quality.Text = $"Quality: {Container.Quality.GetVideoQualityLabel()}";
|
|
duration.Text = $"Duration: {Container.Duration}";
|
|
channel.Text = $"Author: {Container.Channel}";
|
|
|
|
progressPanel.Visibility = Visibility.Collapsed;
|
|
donePanel.Visibility = Visibility.Visible;
|
|
}
|
|
|
|
void Download(string url)
|
|
{
|
|
|
|
}
|
|
|
|
private void UpdateInfo(object sender, DownloadProgressChangedEventArgs e)
|
|
{
|
|
progressBar.Value = e.ProgressPercentage;
|
|
perc.Text = $"{e.ProgressPercentage}%";
|
|
}
|
|
|
|
private void DownloadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
|
|
{
|
|
/*progressPanel.Visibility = Visibility.Collapsed;
|
|
donePanel.Visibility = Visibility.Visible;
|
|
|
|
string node = $@"<item>
|
|
<title{title.Text}></title>
|
|
<snippet>
|
|
<quality>{quality.Text.Split(' ')[1]}</quality>
|
|
<duration>{duration.Text.Split(' ')[1]}</duration>
|
|
<author>{channel.Text.Split(' ')[1]}</author>
|
|
</snippet>
|
|
<details>
|
|
<path>{uri}</path>
|
|
<id>{Id}</id>
|
|
</details>
|
|
</item>";
|
|
|
|
DownloadComplete.Invoke(this, node);*/
|
|
}
|
|
|
|
private async void open_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
await Launcher.LaunchUriAsync(Container.Path);
|
|
}
|
|
|
|
private void gotoOriginal_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
Methods.MainPage.GoToVideo(Container.Id);
|
|
}
|
|
|
|
public void Cancel()
|
|
{
|
|
|
|
}
|
|
|
|
private void cancel_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
/*if(client.IsBusy)
|
|
{
|
|
MessageDialog dialog = new MessageDialog("Are you sure?", "Cancelling download");
|
|
|
|
dialog.Commands.Add(new UICommand("Yes", (command) =>
|
|
{
|
|
status.Text = "Cancelling...";
|
|
progressBar.IsIndeterminate = true;
|
|
cancel.IsEnabled = false;
|
|
client.CancelAsync();
|
|
DownloadCanceled.Invoke(this, null);
|
|
}));
|
|
dialog.Commands.Add(new UICommand("No"));
|
|
|
|
dialog.DefaultCommandIndex = 1;
|
|
await dialog.ShowAsync();
|
|
}*/
|
|
}
|
|
}
|
|
}
|