1.0-dev11 (Notifications added, removing task after success option added, deleting video temp after error option added)
This commit is contained in:
@@ -17,7 +17,7 @@ namespace VDownload.Core.Services
|
|||||||
{
|
{
|
||||||
{ "delete_temp_on_start", true },
|
{ "delete_temp_on_start", true },
|
||||||
{ "twitch_vod_passive_trim", true },
|
{ "twitch_vod_passive_trim", true },
|
||||||
{ "twitch_vod_downloading_chunk_retry_after_error", true },
|
{ "twitch_vod_downloading_chunk_retry_after_error", false },
|
||||||
{ "twitch_vod_downloading_chunk_max_retries", 10 },
|
{ "twitch_vod_downloading_chunk_max_retries", 10 },
|
||||||
{ "twitch_vod_downloading_chunk_retries_delay", 5000 },
|
{ "twitch_vod_downloading_chunk_retries_delay", 5000 },
|
||||||
{ "media_transcoding_use_hardware_acceleration", true },
|
{ "media_transcoding_use_hardware_acceleration", true },
|
||||||
@@ -32,7 +32,10 @@ namespace VDownload.Core.Services
|
|||||||
{ "custom_temp_location", false },
|
{ "custom_temp_location", false },
|
||||||
{ "max_active_video_task", 5 },
|
{ "max_active_video_task", 5 },
|
||||||
{ "replace_output_file_if_exists", false },
|
{ "replace_output_file_if_exists", false },
|
||||||
{ "remove_task_when_successfully_ended", false }
|
{ "remove_task_when_successfully_ended", false },
|
||||||
|
{ "delete_task_temp_when_ended_with_error", false },
|
||||||
|
{ "show_notification_when_task_ended_successfully", false },
|
||||||
|
{ "show_notification_when_task_ended_unsuccessfully", false }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@@ -266,7 +267,7 @@ namespace VDownload.Core.Services.Sources.Twitch
|
|||||||
private static async Task<byte[]> DownloadChunkAsync(Uri chunkUrl, CancellationToken cancellationToken = default)
|
private static async Task<byte[]> DownloadChunkAsync(Uri chunkUrl, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
int retriesCount = 0;
|
int retriesCount = 0;
|
||||||
while ((bool)Config.GetValue("twitch_vod_downloading_chunk_retry_after_error") && retriesCount < (int)Config.GetValue("twitch_vod_downloading_chunk_max_retries"))
|
while (true)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
try
|
try
|
||||||
@@ -276,13 +277,16 @@ namespace VDownload.Core.Services.Sources.Twitch
|
|||||||
return await client.DownloadDataTaskAsync(chunkUrl);
|
return await client.DownloadDataTaskAsync(chunkUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch (WebException wex)
|
||||||
{
|
{
|
||||||
retriesCount++;
|
if ((bool)Config.GetValue("twitch_vod_downloading_chunk_retry_after_error") && retriesCount < (int)Config.GetValue("twitch_vod_downloading_chunk_max_retries"))
|
||||||
await Task.Delay((int)Config.GetValue("twitch_vod_downloading_chunk_retries_delay"));
|
{
|
||||||
|
retriesCount++;
|
||||||
|
await Task.Delay((int)Config.GetValue("twitch_vod_downloading_chunk_retries_delay"));
|
||||||
|
}
|
||||||
|
else throw wex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new WebException("An error occurs while downloading a Twitch VOD chunk");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WRITE CHUNK TO FILE
|
// WRITE CHUNK TO FILE
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ namespace VDownload
|
|||||||
protected override async void OnLaunched(LaunchActivatedEventArgs e)
|
protected override async void OnLaunched(LaunchActivatedEventArgs e)
|
||||||
{
|
{
|
||||||
// Rebuild configuration file
|
// Rebuild configuration file
|
||||||
Config.Rebuild();
|
//Config.Rebuild();
|
||||||
|
Config.SetDefault();
|
||||||
|
|
||||||
// Delete temp on start
|
// Delete temp on start
|
||||||
if ((bool)Config.GetValue("delete_temp_on_start"))
|
if ((bool)Config.GetValue("delete_temp_on_start"))
|
||||||
|
|||||||
@@ -205,6 +205,9 @@ The number in the numberbox indicades how many videos will be got from playlist.
|
|||||||
<data name="HomeTaskPanelStateTextDownloading" xml:space="preserve">
|
<data name="HomeTaskPanelStateTextDownloading" xml:space="preserve">
|
||||||
<value>Downloading</value>
|
<value>Downloading</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="HomeTaskPanelStateTextError" xml:space="preserve">
|
||||||
|
<value>An error occured</value>
|
||||||
|
</data>
|
||||||
<data name="HomeTaskPanelStateTextFinalizing" xml:space="preserve">
|
<data name="HomeTaskPanelStateTextFinalizing" xml:space="preserve">
|
||||||
<value>Finalizing</value>
|
<value>Finalizing</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -259,6 +262,18 @@ The number in the numberbox indicades how many videos will be got from playlist.
|
|||||||
<data name="MediaTypeOnlyVideoText" xml:space="preserve">
|
<data name="MediaTypeOnlyVideoText" xml:space="preserve">
|
||||||
<value>Only video</value>
|
<value>Only video</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="NotificationTaskEndedSuccessfullyDescription" xml:space="preserve">
|
||||||
|
<value>downloading ended successfully</value>
|
||||||
|
</data>
|
||||||
|
<data name="NotificationTaskEndedSuccessfullyHeader" xml:space="preserve">
|
||||||
|
<value>Video downloading ended successfully</value>
|
||||||
|
</data>
|
||||||
|
<data name="NotificationTaskEndedUnsuccessfullyDescription" xml:space="preserve">
|
||||||
|
<value>an error occured</value>
|
||||||
|
</data>
|
||||||
|
<data name="NotificationTaskEndedUnsuccessfullyHeader" xml:space="preserve">
|
||||||
|
<value>Video downloading ended unsuccessfully</value>
|
||||||
|
</data>
|
||||||
<data name="SourcesMainPageHeaderText.Text" xml:space="preserve">
|
<data name="SourcesMainPageHeaderText.Text" xml:space="preserve">
|
||||||
<value>Sources</value>
|
<value>Sources</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -295,4 +310,7 @@ The number in the numberbox indicades how many videos will be got from playlist.
|
|||||||
<data name="SourcesTwitchSettingControlDescriptionNotLoggedIn" xml:space="preserve">
|
<data name="SourcesTwitchSettingControlDescriptionNotLoggedIn" xml:space="preserve">
|
||||||
<value>Not logged in. Twitch authentication is required to download videos.</value>
|
<value>Not logged in. Twitch authentication is required to download videos.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TaskErrorInternetConnection" xml:space="preserve">
|
||||||
|
<value>Internet connection error</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -322,6 +322,9 @@
|
|||||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
||||||
<Version>6.2.13</Version>
|
<Version>6.2.13</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
|
||||||
|
<Version>7.1.2</Version>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Toolkit.Uwp.UI">
|
<PackageReference Include="Microsoft.Toolkit.Uwp.UI">
|
||||||
<Version>7.1.2</Version>
|
<Version>7.1.2</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ namespace VDownload.Views.Home
|
|||||||
catch (WebException wex)
|
catch (WebException wex)
|
||||||
{
|
{
|
||||||
HomeOptionsBarSearchingStatusControl.Content = HomeOptionsBarSearchingStatusErrorImage;
|
HomeOptionsBarSearchingStatusControl.Content = HomeOptionsBarSearchingStatusErrorImage;
|
||||||
if (wex.Response == null)
|
if (wex.Response is null)
|
||||||
{
|
{
|
||||||
ContentDialog internetAccessErrorDialog = new ContentDialog
|
ContentDialog internetAccessErrorDialog = new ContentDialog
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using Microsoft.Toolkit.Uwp.Notifications;
|
||||||
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using VDownload.Core.Enums;
|
using VDownload.Core.Enums;
|
||||||
@@ -53,7 +55,7 @@ namespace VDownload.Views.Home
|
|||||||
Location = location;
|
Location = location;
|
||||||
|
|
||||||
// Set metadata
|
// Set metadata
|
||||||
ThumbnailImage = (BitmapImage)ImagesRes["UnknownThumbnailImage"];
|
ThumbnailImage = VideoService.Thumbnail != null ? new BitmapImage { UriSource = VideoService.Thumbnail } : (BitmapImage)ImagesRes["UnknownThumbnailImage"];
|
||||||
SourceImage = new BitmapIcon { UriSource = new Uri($"ms-appx:///Assets/Sources/{VideoService.GetType().Namespace.Split(".").Last()}.png"), ShowAsMonochrome = false };
|
SourceImage = new BitmapIcon { UriSource = new Uri($"ms-appx:///Assets/Sources/{VideoService.GetType().Namespace.Split(".").Last()}.png"), ShowAsMonochrome = false };
|
||||||
Title = VideoService.Title;
|
Title = VideoService.Title;
|
||||||
Author = VideoService.Author;
|
Author = VideoService.Author;
|
||||||
@@ -144,6 +146,8 @@ namespace VDownload.Views.Home
|
|||||||
tempFolder = ApplicationData.Current.TemporaryFolder;
|
tempFolder = ApplicationData.Current.TemporaryFolder;
|
||||||
tempFolder = await tempFolder.CreateFolderAsync(uniqueID);
|
tempFolder = await tempFolder.CreateFolderAsync(uniqueID);
|
||||||
|
|
||||||
|
bool endedWithError = false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Throw exception if cancellation requested
|
// Throw exception if cancellation requested
|
||||||
@@ -212,6 +216,12 @@ namespace VDownload.Views.Home
|
|||||||
HomeTaskPanelStateText.Text = $"{ResourceLoader.GetForCurrentView().GetString("HomeTaskPanelStateTextDone")} ({(Math.Floor(taskStopwatch.Elapsed.TotalHours) > 0 ? $"{ Math.Floor(taskStopwatch.Elapsed.TotalHours):0}:" : "")}{taskStopwatch.Elapsed.Minutes:00}:{taskStopwatch.Elapsed.Seconds:00})";
|
HomeTaskPanelStateText.Text = $"{ResourceLoader.GetForCurrentView().GetString("HomeTaskPanelStateTextDone")} ({(Math.Floor(taskStopwatch.Elapsed.TotalHours) > 0 ? $"{ Math.Floor(taskStopwatch.Elapsed.TotalHours):0}:" : "")}{taskStopwatch.Elapsed.Minutes:00}:{taskStopwatch.Elapsed.Seconds:00})";
|
||||||
HomeTaskPanelStateProgressBar.Visibility = Visibility.Collapsed;
|
HomeTaskPanelStateProgressBar.Visibility = Visibility.Collapsed;
|
||||||
|
|
||||||
|
// Show notification
|
||||||
|
if ((bool)Config.GetValue("show_notification_when_task_ended_successfully"))
|
||||||
|
new ToastContentBuilder()
|
||||||
|
.AddText(ResourceLoader.GetForCurrentView().GetString("NotificationTaskEndedSuccessfullyHeader"))
|
||||||
|
.AddText($"\"{Title}\" - {ResourceLoader.GetForCurrentView().GetString("NotificationTaskEndedSuccessfullyDescription")}")
|
||||||
|
.Show();
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
@@ -220,19 +230,46 @@ namespace VDownload.Views.Home
|
|||||||
HomeTaskPanelStateText.Text = ResourceLoader.GetForCurrentView().GetString("HomeTaskPanelStateTextCancelled");
|
HomeTaskPanelStateText.Text = ResourceLoader.GetForCurrentView().GetString("HomeTaskPanelStateTextCancelled");
|
||||||
HomeTaskPanelStateProgressBar.Visibility = Visibility.Collapsed;
|
HomeTaskPanelStateProgressBar.Visibility = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
|
catch (WebException ex)
|
||||||
|
{
|
||||||
|
string errorInfo;
|
||||||
|
if (ex.Response is null) errorInfo = ResourceLoader.GetForCurrentView().GetString("TaskErrorInternetConnection");
|
||||||
|
else throw ex;
|
||||||
|
|
||||||
|
// Set state controls
|
||||||
|
HomeTaskPanelStateIcon.Source = (SvgImageSource)IconsRes["StateErrorIcon"];
|
||||||
|
HomeTaskPanelStateText.Text = $"{ResourceLoader.GetForCurrentView().GetString("HomeTaskPanelStateTextError")} ({errorInfo})";
|
||||||
|
HomeTaskPanelStateProgressBar.Visibility = Visibility.Collapsed;
|
||||||
|
|
||||||
|
// Show notification
|
||||||
|
if ((bool)Config.GetValue("show_notification_when_task_ended_unsuccessfully"))
|
||||||
|
new ToastContentBuilder()
|
||||||
|
.AddText(ResourceLoader.GetForCurrentView().GetString("NotificationTaskEndedUnsuccessfullyHeader"))
|
||||||
|
.AddText($"\"{Title}\" - {ResourceLoader.GetForCurrentView().GetString("NotificationTaskEndedUnsuccessfullyDescription")} ({errorInfo})")
|
||||||
|
.Show();
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
// Change icon
|
|
||||||
HomeTaskPanelStartStopButton.Icon = new SymbolIcon(Symbol.Download);
|
|
||||||
|
|
||||||
// Set video status
|
// Set video status
|
||||||
TaskStatus = Core.Enums.TaskStatus.Idle;
|
TaskStatus = Core.Enums.TaskStatus.Idle;
|
||||||
|
|
||||||
// Delete temporary files
|
// Change icon
|
||||||
await tempFolder.DeleteAsync();
|
HomeTaskPanelStartStopButton.Icon = new SymbolIcon(Symbol.Download);
|
||||||
|
|
||||||
// Dispose unique id
|
if (!endedWithError || (bool)Config.GetValue("delete_task_temp_when_ended_with_error"))
|
||||||
TaskId.Dispose(uniqueID);
|
{
|
||||||
|
// Delete temporary files
|
||||||
|
await tempFolder.DeleteAsync();
|
||||||
|
|
||||||
|
// Dispose unique id
|
||||||
|
TaskId.Dispose(uniqueID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!endedWithError && !CancellationTokenSource.IsCancellationRequested && (bool)Config.GetValue("remove_task_when_successfully_ended"))
|
||||||
|
{
|
||||||
|
// Remove task when successfully ended
|
||||||
|
TaskRemovingRequested?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -268,7 +305,7 @@ namespace VDownload.Views.Home
|
|||||||
private void HomeTaskPanelRemoveButton_Click(object sender, RoutedEventArgs e)
|
private void HomeTaskPanelRemoveButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (TaskStatus == Core.Enums.TaskStatus.InProgress || TaskStatus == Core.Enums.TaskStatus.Waiting) CancellationTokenSource.Cancel();
|
if (TaskStatus == Core.Enums.TaskStatus.InProgress || TaskStatus == Core.Enums.TaskStatus.Waiting) CancellationTokenSource.Cancel();
|
||||||
TaskRemovingRequested?.Invoke(sender, EventArgs.Empty);
|
TaskRemovingRequested?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user