Archived
1
0

Core refactoring (app doesn't work)

This commit is contained in:
Michael Gordeev
2020-05-09 23:16:19 +03:00
parent 2b1f06dd93
commit 2a987e33a2
35 changed files with 1135 additions and 817 deletions
+42
View File
@@ -0,0 +1,42 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;
using YoutubeExplode;
using YoutubeExplode.Videos.Streams;
namespace FoxTube.Models
{
public enum DownloadState { Initializing, Downloading, Cancelling }
public class DownloadItem : SavedVideo
{
public DownloadState State { get; private set; } = DownloadState.Initializing;
public IProgress<double> DownloadPercentage { get; set; }
private CancellationTokenSource CTS { get; set; } = new CancellationTokenSource();
public async Task CommenceDownload(IStreamInfo stream, IStorageFile destination)
{
Path = destination.Path;
YoutubeClient client = new YoutubeClient(UserManagement.Service.HttpClient);
State = DownloadState.Downloading;
Task task = client.Videos.Streams.DownloadAsync(stream, Path, DownloadPercentage, CTS.Token);
await task.ConfigureAwait(false);
if (!task.IsCanceled)
return;
await destination.DeleteAsync(StorageDeleteOption.PermanentDelete);
throw new OperationCanceledException();
}
public void Cancel()
{
State = DownloadState.Cancelling;
CTS.Cancel();
}
}
}