1.0-dev18 (prerelease 1 completed)

This commit is contained in:
2022-05-15 22:13:47 +02:00
Unverified
parent 7acaeb24de
commit e36c1404ee
61 changed files with 1004 additions and 144 deletions

View File

@@ -1,24 +0,0 @@
using System;
namespace VDownload.Core.EventArgs
{
public class DownloadTaskEndedSuccessfullyEventArgs : System.EventArgs
{
#region CONSTRUCTORS
public DownloadTaskEndedSuccessfullyEventArgs(TimeSpan elapsedTime)
{
ElapsedTime = elapsedTime;
}
#endregion
#region PROPERTIES
public TimeSpan ElapsedTime { get; private set; }
#endregion
}
}

View File

@@ -1,24 +0,0 @@
using System;
namespace VDownload.Core.EventArgs
{
public class DownloadTaskEndedUnsuccessfullyEventArgs : System.EventArgs
{
#region CONSTRUCTORS
public DownloadTaskEndedUnsuccessfullyEventArgs(Exception exception)
{
Exception = exception;
}
#endregion
#region PROPERTIES
public Exception Exception { get; private set; }
#endregion
}
}

View File

@@ -1,24 +0,0 @@
using System;
namespace VDownload.Core.EventArgs
{
public class DownloadTaskScheduledEventArgs : System.EventArgs
{
#region CONSTRUCTORS
public DownloadTaskScheduledEventArgs(DateTime scheduledFor)
{
ScheduledFor = scheduledFor;
}
#endregion
#region PROPERTIES
public DateTime ScheduledFor { get; private set; }
#endregion
}
}

View File

@@ -0,0 +1,61 @@
using System;
using VDownload.Core.Enums;
namespace VDownload.Core.EventArgs
{
public class DownloadTaskStatusChangedEventArgs : System.EventArgs
{
#region CONSTRUCTORS
public DownloadTaskStatusChangedEventArgs(DownloadTaskStatus status)
{
Status = status;
}
public DownloadTaskStatusChangedEventArgs(DownloadTaskStatus status, DateTime scheduledFor)
{
Status = status;
ScheduledFor = scheduledFor;
}
public DownloadTaskStatusChangedEventArgs(DownloadTaskStatus status, double progress)
{
Status = status;
if (Status == DownloadTaskStatus.Downloading)
{
DownloadingProgress = progress;
}
else if (Status == DownloadTaskStatus.Processing)
{
ProcessingProgress = progress;
}
}
public DownloadTaskStatusChangedEventArgs(DownloadTaskStatus status, TimeSpan elapsedTime)
{
Status = status;
ElapsedTime = elapsedTime;
}
public DownloadTaskStatusChangedEventArgs(DownloadTaskStatus status, Exception exception)
{
Status = status;
Exception = exception;
}
#endregion
#region PROPERTIES
public DownloadTaskStatus Status { get; private set; }
public DateTime ScheduledFor { get; private set; }
public double DownloadingProgress { get; private set; }
public double ProcessingProgress { get; private set; }
public TimeSpan ElapsedTime { get; private set; }
public Exception Exception { get; private set; }
#endregion
}
}

View File

@@ -26,7 +26,6 @@ namespace VDownload.Core.Services
{ "default_video_extension", (int)VideoFileExtension.MP4 },
{ "default_audio_extension", (int)AudioFileExtension.MP3 },
{ "custom_media_location", false },
{ "custom_temp_location", false },
{ "max_active_video_task", 5 },
{ "replace_output_file_if_exists", false },
{ "remove_task_when_successfully_ended", false },

View File

@@ -27,6 +27,7 @@ namespace VDownload.Core.Structs
Schedule = schedule;
Status = DownloadTaskStatus.Idle;
LastStatusChangedEventArgs = new DownloadTaskStatusChangedEventArgs(Status);
CancellationTokenSource = new CancellationTokenSource();
}
@@ -44,14 +45,9 @@ namespace VDownload.Core.Structs
public OutputFile File { get; set; }
public double Schedule { get; set; }
public DownloadTaskStatus Status { get; private set; }
public DownloadTaskStatusChangedEventArgs LastStatusChangedEventArgs { get; private set; }
public CancellationTokenSource CancellationTokenSource { get; private set; }
public DateTime ScheduledFor { get; private set; }
public double DownloadingProgress { get; private set; }
public double ProcessingProgress { get; private set; }
public TimeSpan ElapsedTime { get; private set; }
public Exception Exception { get; private set; }
#endregion
@@ -60,30 +56,35 @@ namespace VDownload.Core.Structs
public async Task Run(bool delayWhenOnMeteredConnection)
{
StatusChanged.Invoke(this, System.EventArgs.Empty);
StatusChanged.Invoke(this, new DownloadTaskStatusChangedEventArgs(Status));
CancellationTokenSource = new CancellationTokenSource();
if (Schedule > 0)
{
ScheduledFor = DateTime.Now.AddMinutes(Schedule);
DateTime scheduleFor = DateTime.Now.AddMinutes(Schedule);
Status = DownloadTaskStatus.Scheduled;
StatusChanged.Invoke(this, System.EventArgs.Empty);
while (DateTime.Now < ScheduledFor && !CancellationTokenSource.Token.IsCancellationRequested) await Task.Delay(100);
LastStatusChangedEventArgs = new DownloadTaskStatusChangedEventArgs(Status, scheduleFor);
StatusChanged.Invoke(this, LastStatusChangedEventArgs);
while (DateTime.Now < scheduleFor && !CancellationTokenSource.Token.IsCancellationRequested)
{
await Task.Delay(100);
}
}
Status = DownloadTaskStatus.Queued;
StatusChanged.Invoke(this, System.EventArgs.Empty);
LastStatusChangedEventArgs = new DownloadTaskStatusChangedEventArgs(Status);
StatusChanged.Invoke(this, LastStatusChangedEventArgs);
await DownloadTasksCollectionManagement.WaitInQueue(delayWhenOnMeteredConnection, CancellationTokenSource.Token);
if (!CancellationTokenSource.Token.IsCancellationRequested)
{
DownloadingProgress = 0;
Status = DownloadTaskStatus.Downloading;
StatusChanged.Invoke(this, System.EventArgs.Empty);
LastStatusChangedEventArgs = new DownloadTaskStatusChangedEventArgs(Status, 0);
StatusChanged.Invoke(this, LastStatusChangedEventArgs);
StorageFolder tempFolder;
if ((bool)Config.GetValue("custom_temp_location") && StorageApplicationPermissions.FutureAccessList.ContainsItem("custom_temp_location"))
if (StorageApplicationPermissions.FutureAccessList.ContainsItem("custom_temp_location"))
{
tempFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync("custom_temp_location");
}
@@ -112,7 +113,8 @@ namespace VDownload.Core.Structs
session.Dispose();
Status = DownloadTaskStatus.Finalizing;
StatusChanged.Invoke(this, System.EventArgs.Empty);
LastStatusChangedEventArgs = new DownloadTaskStatusChangedEventArgs(Status);
StatusChanged.Invoke(this, LastStatusChangedEventArgs);
StorageFile outputFile = await File.Create();
@@ -121,16 +123,16 @@ namespace VDownload.Core.Structs
taskStopwatch.Stop();
ElapsedTime = taskStopwatch.Elapsed;
Status = DownloadTaskStatus.EndedSuccessfully;
StatusChanged.Invoke(this, System.EventArgs.Empty);
LastStatusChangedEventArgs = new DownloadTaskStatusChangedEventArgs(Status, taskStopwatch.Elapsed);
StatusChanged.Invoke(this, LastStatusChangedEventArgs);
}
catch (Exception ex)
{
endedWithError = true;
Exception = ex;
Status = DownloadTaskStatus.EndedUnsuccessfully;
StatusChanged.Invoke(this, System.EventArgs.Empty);
LastStatusChangedEventArgs = new DownloadTaskStatusChangedEventArgs(Status, ex);
StatusChanged.Invoke(this, LastStatusChangedEventArgs);
}
finally
{
@@ -143,24 +145,24 @@ namespace VDownload.Core.Structs
}
else
{
Exception = new OperationCanceledException(CancellationTokenSource.Token);
Status = DownloadTaskStatus.EndedUnsuccessfully;
StatusChanged.Invoke(this, System.EventArgs.Empty);
LastStatusChangedEventArgs = new DownloadTaskStatusChangedEventArgs(Status, new OperationCanceledException(CancellationTokenSource.Token));
StatusChanged.Invoke(this, LastStatusChangedEventArgs);
}
}
private void DownloadingProgressChanged(object sender, ProgressChangedEventArgs e)
{
DownloadingProgress = e.Progress;
Status = DownloadTaskStatus.Downloading;
StatusChanged.Invoke(this, System.EventArgs.Empty);
LastStatusChangedEventArgs = new DownloadTaskStatusChangedEventArgs(Status, e.Progress);
StatusChanged.Invoke(this, LastStatusChangedEventArgs);
}
private void ProcessingProgressChanged(object sender, ProgressChangedEventArgs e)
{
ProcessingProgress = e.Progress;
Status = DownloadTaskStatus.Processing;
StatusChanged.Invoke(this, System.EventArgs.Empty);
LastStatusChangedEventArgs = new DownloadTaskStatusChangedEventArgs(Status, e.Progress);
StatusChanged.Invoke(this, LastStatusChangedEventArgs);
}
#endregion
@@ -169,7 +171,7 @@ namespace VDownload.Core.Structs
#region EVENT
public event EventHandler StatusChanged;
public event EventHandler<DownloadTaskStatusChangedEventArgs> StatusChanged;
#endregion
}

View File

@@ -128,11 +128,9 @@
<Compile Include="Enums\VideoFileExtension.cs" />
<Compile Include="Enums\VideoSource.cs" />
<Compile Include="Enums\DownloadTaskStatus.cs" />
<Compile Include="EventArgs\DownloadTaskEndedUnsuccessfullyEventArgs.cs" />
<Compile Include="EventArgs\DownloadTaskEndedSuccessfullyEventArgs.cs" />
<Compile Include="EventArgs\DownloadTaskScheduledEventArgs.cs" />
<Compile Include="EventArgs\ProgressChangedEventArgs.cs" />
<Compile Include="EventArgs\DownloadTasksAddingRequestedEventArgs.cs" />
<Compile Include="EventArgs\DownloadTaskStatusChangedEventArgs.cs" />
<Compile Include="EventArgs\ProgressChangedEventArgs.cs" />
<Compile Include="EventArgs\PlaylistSearchSuccessedEventArgs.cs" />
<Compile Include="EventArgs\SubscriptionLoadSuccessedEventArgs.cs" />
<Compile Include="EventArgs\VideoSearchSuccessedEventArgs.cs" />