fixes, errors handling
This commit is contained in:
@@ -117,6 +117,21 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
|
<data name="DialogErrorMessageNoInternetConnection" xml:space="preserve">
|
||||||
|
<value>No internet connection. Try again later.</value>
|
||||||
|
</data>
|
||||||
|
<data name="DialogErrorTitle" xml:space="preserve">
|
||||||
|
<value>Error</value>
|
||||||
|
</data>
|
||||||
|
<data name="ErrorDownloadingTimeout" xml:space="preserve">
|
||||||
|
<value>Downloading timeout. Check your internet connection and try again later.</value>
|
||||||
|
</data>
|
||||||
|
<data name="ErrorFFmpeg" xml:space="preserve">
|
||||||
|
<value>FFmpeg exited with error.</value>
|
||||||
|
</data>
|
||||||
|
<data name="ErrorFFmpegPath" xml:space="preserve">
|
||||||
|
<value>No FFmpeg executables found. Check path in settings and try again.</value>
|
||||||
|
</data>
|
||||||
<data name="StatusCancelled.Text" xml:space="preserve">
|
<data name="StatusCancelled.Text" xml:space="preserve">
|
||||||
<value>Cancelled</value>
|
<value>Cancelled</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ using System.IO;
|
|||||||
using VDownload.Services.UI.Notifications;
|
using VDownload.Services.UI.Notifications;
|
||||||
using VDownload.Services.UI.StringResources;
|
using VDownload.Services.UI.StringResources;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
|
using Instances.Exceptions;
|
||||||
|
using FFMpegCore.Exceptions;
|
||||||
|
|
||||||
namespace VDownload.Core.Tasks
|
namespace VDownload.Core.Tasks
|
||||||
{
|
{
|
||||||
@@ -140,7 +143,11 @@ namespace VDownload.Core.Tasks
|
|||||||
|
|
||||||
await _settingsService.Load();
|
await _settingsService.Load();
|
||||||
|
|
||||||
string tempDirectory = $"{_settingsService.Data.Common.Temp.Directory}\\{_configurationService.Common.Path.Temp.TasksDirectory}\\{Id}";
|
string tempDirectory = $"{_settingsService.Data.Common.Temp.Directory}\\{_configurationService.Common.Path.Temp.TasksDirectory}\\{Guid.NewGuid()}";
|
||||||
|
if (Directory.Exists(tempDirectory))
|
||||||
|
{
|
||||||
|
Directory.Delete(tempDirectory, true);
|
||||||
|
}
|
||||||
Directory.CreateDirectory(tempDirectory);
|
Directory.CreateDirectory(tempDirectory);
|
||||||
|
|
||||||
List<string> content = new List<string>()
|
List<string> content = new List<string>()
|
||||||
@@ -180,10 +187,11 @@ namespace VDownload.Core.Tasks
|
|||||||
.JoinProgressReporter(onProgressProcessing, downloadResult.NewDuration);
|
.JoinProgressReporter(onProgressProcessing, downloadResult.NewDuration);
|
||||||
await ffmpegBuilder.RunAsync(downloadResult.File, outputPath);
|
await ffmpegBuilder.RunAsync(downloadResult.File, outputPath);
|
||||||
|
|
||||||
|
StorageFile outputFile = await StorageFile.GetFileFromPathAsync(outputPath);
|
||||||
|
|
||||||
UpdateStatusWithDispatcher(DownloadTaskStatus.Finalizing);
|
UpdateStatusWithDispatcher(DownloadTaskStatus.Finalizing);
|
||||||
|
|
||||||
string destination = $"{DownloadOptions.Directory}\\{DownloadOptions.Filename}.{DownloadOptions.Extension}";
|
await Finalizing(outputFile);
|
||||||
File.Copy(outputPath, destination, true);
|
|
||||||
|
|
||||||
UpdateStatusWithDispatcher(DownloadTaskStatus.EndedSuccessfully);
|
UpdateStatusWithDispatcher(DownloadTaskStatus.EndedSuccessfully);
|
||||||
|
|
||||||
@@ -199,7 +207,26 @@ namespace VDownload.Core.Tasks
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
UpdateErrorWithDispatcher(ex.Message);
|
string message;
|
||||||
|
|
||||||
|
if (ex is TaskCanceledException || ex is HttpRequestException)
|
||||||
|
{
|
||||||
|
message = _stringResourcesService.HomeDownloadsViewResources.Get("ErrorDownloadingTimeout");
|
||||||
|
}
|
||||||
|
else if (ex is InstanceFileNotFoundException)
|
||||||
|
{
|
||||||
|
message = _stringResourcesService.HomeDownloadsViewResources.Get("ErrorFFmpegPath");
|
||||||
|
}
|
||||||
|
else if (ex is FFMpegException)
|
||||||
|
{
|
||||||
|
message = _stringResourcesService.HomeDownloadsViewResources.Get("ErrorFFmpeg");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message = ex.Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateErrorWithDispatcher(message);
|
||||||
UpdateStatusWithDispatcher(DownloadTaskStatus.EndedUnsuccessfully);
|
UpdateStatusWithDispatcher(DownloadTaskStatus.EndedUnsuccessfully);
|
||||||
|
|
||||||
if (_settingsService.Data.Common.Notifications.OnUnsuccessful)
|
if (_settingsService.Data.Common.Notifications.OnUnsuccessful)
|
||||||
@@ -218,11 +245,19 @@ namespace VDownload.Core.Tasks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateStatusWithDispatcher(DownloadTaskStatus status) => _dispatcherQueue.TryEnqueue(() => Status = status);
|
protected async Task Finalizing(StorageFile outputFile)
|
||||||
|
{
|
||||||
|
StorageFolder destination = await StorageFolder.GetFolderFromPathAsync(DownloadOptions.Directory);
|
||||||
|
|
||||||
private void UpdateProgressWithDispatcher(double progress) => _dispatcherQueue.TryEnqueue(() => Progress = progress);
|
string filename = $"{DownloadOptions.Filename}.{DownloadOptions.Extension}";
|
||||||
|
await outputFile.CopyAsync(destination, filename, NameCollisionOption.ReplaceExisting);
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateErrorWithDispatcher(string message) => _dispatcherQueue.TryEnqueue(() => Error = message);
|
protected void UpdateStatusWithDispatcher(DownloadTaskStatus status) => _dispatcherQueue.TryEnqueue(() => Status = status);
|
||||||
|
|
||||||
|
protected void UpdateProgressWithDispatcher(double progress) => _dispatcherQueue.TryEnqueue(() => Progress = progress);
|
||||||
|
|
||||||
|
protected void UpdateErrorWithDispatcher(string message) => _dispatcherQueue.TryEnqueue(() => Error = message);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,14 @@ namespace VDownload.Core.ViewModels.Home
|
|||||||
];
|
];
|
||||||
if (idleStatuses.Contains(task.Status))
|
if (idleStatuses.Contains(task.Status))
|
||||||
{
|
{
|
||||||
|
if (!NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable)
|
||||||
|
{
|
||||||
|
string title = _stringResourcesService.HomeDownloadsViewResources.Get("DialogErrorTitle");
|
||||||
|
string message = _stringResourcesService.HomeDownloadsViewResources.Get("DialogErrorMessageNoInternetConnection");
|
||||||
|
await _dialogsService.ShowOk(title, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool continueEnqueue = true;
|
bool continueEnqueue = true;
|
||||||
if (NetworkHelper.Instance.ConnectionInformation.IsInternetOnMeteredConnection)
|
if (NetworkHelper.Instance.ConnectionInformation.IsInternetOnMeteredConnection)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ namespace VDownload.Services.Utility.FFmpeg
|
|||||||
protected string _inputFile;
|
protected string _inputFile;
|
||||||
protected string _outputFile;
|
protected string _outputFile;
|
||||||
|
|
||||||
|
protected string _audioCodec;
|
||||||
|
protected string _videoCodec;
|
||||||
|
|
||||||
protected FFOptions _options;
|
protected FFOptions _options;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -103,6 +106,10 @@ namespace VDownload.Services.Utility.FFmpeg
|
|||||||
_inputFile = inputFile;
|
_inputFile = inputFile;
|
||||||
_outputFile = outputFile;
|
_outputFile = outputFile;
|
||||||
|
|
||||||
|
IMediaAnalysis analysis = await FFProbe.AnalyseAsync(_inputFile, _options);
|
||||||
|
_audioCodec = analysis.AudioStreams.First().CodecName;
|
||||||
|
_videoCodec = analysis.VideoStreams.First().CodecName;
|
||||||
|
|
||||||
FFMpegArgumentProcessor ffmpegArguments = FFMpegArguments.FromFileInput(inputFile, true, async (options) => await BuildInputArgumentOptions(options))
|
FFMpegArgumentProcessor ffmpegArguments = FFMpegArguments.FromFileInput(inputFile, true, async (options) => await BuildInputArgumentOptions(options))
|
||||||
.OutputToFile(outputFile, true, async (options) => await BuildOutputArgumentOptions(options));
|
.OutputToFile(outputFile, true, async (options) => await BuildOutputArgumentOptions(options));
|
||||||
|
|
||||||
@@ -154,17 +161,13 @@ namespace VDownload.Services.Utility.FFmpeg
|
|||||||
|
|
||||||
private async Task BuildOutputArgumentOptions(FFMpegArgumentOptions options)
|
private async Task BuildOutputArgumentOptions(FFMpegArgumentOptions options)
|
||||||
{
|
{
|
||||||
IMediaAnalysis analysis = await FFProbe.AnalyseAsync(_inputFile, _options);
|
|
||||||
string audioCodec = analysis.AudioStreams.First().CodecName;
|
|
||||||
string videoCodec = analysis.VideoStreams.First().CodecName;
|
|
||||||
|
|
||||||
string extension = Path.GetExtension(_outputFile).Replace(".", string.Empty);
|
string extension = Path.GetExtension(_outputFile).Replace(".", string.Empty);
|
||||||
Data.Configuration.Models.Muxer muxer = _configurationService.Common.Processing.Muxers.First(x => x.Extension == extension);
|
Data.Configuration.Models.Muxer muxer = _configurationService.Common.Processing.Muxers.First(x => x.Extension == extension);
|
||||||
|
|
||||||
if (_mediaType != MediaType.OnlyAudio)
|
if (_mediaType != MediaType.OnlyAudio)
|
||||||
{
|
{
|
||||||
IEnumerable<string> availableCodecs = muxer.VideoCodecs;
|
IEnumerable<string> availableCodecs = muxer.VideoCodecs;
|
||||||
string selectedCodec = availableCodecs.Contains(videoCodec) ? "copy" : availableCodecs.First();
|
string selectedCodec = availableCodecs.Contains(_videoCodec) ? "copy" : availableCodecs.First();
|
||||||
options.WithCustomArgument($"-vcodec {selectedCodec}");
|
options.WithCustomArgument($"-vcodec {selectedCodec}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -175,7 +178,7 @@ namespace VDownload.Services.Utility.FFmpeg
|
|||||||
if (_mediaType != MediaType.OnlyVideo)
|
if (_mediaType != MediaType.OnlyVideo)
|
||||||
{
|
{
|
||||||
IEnumerable<string> availableCodecs = muxer.AudioCodecs;
|
IEnumerable<string> availableCodecs = muxer.AudioCodecs;
|
||||||
string selectedCodec = availableCodecs.Contains(audioCodec) ? "copy" : availableCodecs.First();
|
string selectedCodec = availableCodecs.Contains(_audioCodec) ? "copy" : availableCodecs.First();
|
||||||
options.WithCustomArgument($"-acodec {selectedCodec}");
|
options.WithCustomArgument($"-acodec {selectedCodec}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -145,15 +145,17 @@ namespace VDownload.Sources.Twitch.Models
|
|||||||
{
|
{
|
||||||
token.ThrowIfCancellationRequested();
|
token.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
using (FileStream inputStream = File.OpenRead(path))
|
using (FileStream inputStream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||||
{
|
{
|
||||||
inputStream.CopyTo(outputStream);
|
inputStream.CopyTo(outputStream);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (string item in sourceFiles)
|
||||||
|
{
|
||||||
if (deleteSource)
|
if (deleteSource)
|
||||||
{
|
{
|
||||||
File.Delete(path);
|
File.Delete(item);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,10 +186,7 @@ namespace VDownload.Sources.Twitch.Models
|
|||||||
int retriesCount = 0;
|
int retriesCount = 0;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (token.IsCancellationRequested)
|
token.ThrowIfCancellationRequested();
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
byte[] data = await _httpClient.GetByteArrayAsync(chunk.Url, token);
|
byte[] data = await _httpClient.GetByteArrayAsync(chunk.Url, token);
|
||||||
@@ -195,10 +194,6 @@ namespace VDownload.Sources.Twitch.Models
|
|||||||
onTaskEndSuccessfully.Invoke();
|
onTaskEndSuccessfully.Invoke();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
catch (Exception ex) when (ex is HttpRequestException || ex is TaskCanceledException)
|
catch (Exception ex) when (ex is HttpRequestException || ex is TaskCanceledException)
|
||||||
{
|
{
|
||||||
if (_settingsService.Data.Twitch.Vod.ChunkDownloadingError.Retry && retriesCount < _settingsService.Data.Twitch.Vod.ChunkDownloadingError.RetriesCount)
|
if (_settingsService.Data.Twitch.Vod.ChunkDownloadingError.Retry && retriesCount < _settingsService.Data.Twitch.Vod.ChunkDownloadingError.RetriesCount)
|
||||||
|
|||||||
Reference in New Issue
Block a user