Add some logging to the downloaders, fixed issue with torrents and downloads not matching up.

This commit is contained in:
Roger Far 2021-10-27 18:55:12 -06:00
parent d16e7f0c88
commit 5d58bc9082
8 changed files with 85 additions and 39 deletions

View file

@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.9.1] - 2021-10-24
## [1.9.2] - 2021-10-27
### Changed
- Fixed issue where not the correct torrent was used for a download.
## [1.9.1] - 2021-10-27
### Added
- Added automatic torrent retrying when RealDebrid reports an error on the torrent.

View file

@ -55,7 +55,7 @@
<a class="navbar-item"> Profile </a>
<a class="navbar-item" (click)="logout()"> Logout </a>
<hr class="navbar-divider" />
<div class="navbar-item">Version 1.9.1</div>
<div class="navbar-item">Version 1.9.2</div>
</div>
</div>
</div>

View file

@ -1,6 +1,6 @@
{
"name": "rdt-client",
"version": "1.9.1",
"version": "1.9.2",
"description": "This is a web interface to manage your torrents on Real-Debrid.",
"main": "index.js",
"dependencies": {

View file

@ -6,6 +6,7 @@ using System.Net.Http;
using System.Threading.Tasks;
using Aria2NET;
using RdtClient.Data.Models.Internal;
using Serilog;
namespace RdtClient.Service.Services.Downloaders
{
@ -16,15 +17,17 @@ namespace RdtClient.Service.Services.Downloaders
private const Int32 RetryCount = 5;
private readonly Aria2NetClient _aria2NetClient;
private readonly ILogger _logger;
private readonly String _uri;
private readonly String _filePath;
private readonly Aria2NetClient _aria2NetClient;
private String _gid;
public Aria2cDownloader(String gid, String uri, String filePath, DbSettings settings)
{
_logger = Log.ForContext<Aria2cDownloader>();
_gid = gid;
_uri = uri;
_filePath = filePath;
@ -42,6 +45,8 @@ namespace RdtClient.Service.Services.Downloaders
var path = Path.GetDirectoryName(_filePath);
var fileName = Path.GetFileName(_filePath);
_logger.Debug($"Starting download of {_uri}, writing to path: {path}, fileName: {fileName}");
var isAlreadyAdded = await CheckIfAdded();
if (isAlreadyAdded)
@ -82,17 +87,23 @@ namespace RdtClient.Service.Services.Downloaders
}
});
_logger.Debug($"Added download to Aria2, received ID {_gid}");
await _aria2NetClient.TellStatus(_gid);
_logger.Debug($"Download with ID {_gid} found in Aria2");
return _gid;
}
catch
catch (Exception ex)
{
if (retryCount >= RetryCount)
{
throw;
}
_logger.Debug($"Error starting download: {ex.Message}. Retrying {retryCount}/{RetryCount}");
await Task.Delay(retryCount * 1000);
retryCount++;
@ -102,32 +113,13 @@ namespace RdtClient.Service.Services.Downloaders
public async Task Cancel()
{
if (String.IsNullOrWhiteSpace(_gid))
{
return;
}
try
{
await _aria2NetClient.ForceRemove(_gid);
}
catch
{
// ignored
}
try
{
await _aria2NetClient.RemoveDownloadResult(_gid);
}
catch
{
// ignored
}
await Remove();
}
public async Task Pause()
{
_logger.Debug($"Pausing download {_uri} {_gid}");
if (String.IsNullOrWhiteSpace(_gid))
{
return;
@ -145,6 +137,8 @@ namespace RdtClient.Service.Services.Downloaders
public async Task Resume()
{
_logger.Debug($"Resuming download {_uri} {_gid}");
if (String.IsNullOrWhiteSpace(_gid))
{
return;
@ -176,7 +170,7 @@ namespace RdtClient.Service.Services.Downloaders
if (!String.IsNullOrWhiteSpace(download.ErrorMessage) || download.Status == "error")
{
await Cancel();
await Remove();
DownloadComplete?.Invoke(this, new DownloadCompleteEventArgs
{
Error = $"{download.ErrorCode}: {download.ErrorMessage}"
@ -186,7 +180,9 @@ namespace RdtClient.Service.Services.Downloaders
if (download.Status == "complete" || download.Status == "removed")
{
await Cancel();
_logger.Debug($"Aria2 download found as complete {_gid}");
await Remove();
var retryCount = 0;
while (true)
@ -220,6 +216,34 @@ namespace RdtClient.Service.Services.Downloaders
});
}
private async Task Remove()
{
if (String.IsNullOrWhiteSpace(_gid))
{
return;
}
_logger.Debug($"Remove download {_uri} {_gid} from Aria2");
try
{
await _aria2NetClient.ForceRemove(_gid);
}
catch
{
// ignored
}
try
{
await _aria2NetClient.RemoveDownloadResult(_gid);
}
catch
{
// ignored
}
}
private async Task<Boolean> CheckIfAdded()
{
var allDownloads = await _aria2NetClient.TellAll();

View file

@ -4,6 +4,7 @@ using System.Net;
using System.Threading.Tasks;
using Downloader;
using RdtClient.Data.Models.Internal;
using Serilog;
namespace RdtClient.Service.Services.Downloaders
{
@ -16,8 +17,12 @@ namespace RdtClient.Service.Services.Downloaders
private readonly String _filePath;
private readonly String _uri;
private readonly ILogger _logger;
public MultiDownloader(String uri, String filePath, DbSettings settings)
{
_logger = Log.ForContext<MultiDownloader>();
_uri = uri;
_filePath = filePath;
@ -113,6 +118,8 @@ namespace RdtClient.Service.Services.Downloaders
public async Task<String> Download()
{
_logger.Debug($"Starting download of {_uri}, writing to path: {_filePath}");
await _downloadService.DownloadFileTaskAsync(_uri, _filePath);
return null;
@ -120,6 +127,8 @@ namespace RdtClient.Service.Services.Downloaders
public Task Cancel()
{
_logger.Debug($"Cancelling download {_uri}");
_downloadService.CancelAsync();
return Task.CompletedTask;

View file

@ -2,6 +2,7 @@
using System.IO;
using System.Net;
using System.Threading.Tasks;
using Serilog;
namespace RdtClient.Service.Services.Downloaders
{
@ -22,14 +23,20 @@ namespace RdtClient.Service.Services.Downloaders
private Int64 _bytesLastUpdate;
private DateTime _nextUpdate;
private readonly ILogger _logger;
public SimpleDownloader(String uri, String filePath)
{
_logger = Log.ForContext<Aria2cDownloader>();
_uri = uri;
_filePath = filePath;
}
public Task<String> Download()
{
_logger.Debug($"Starting download of {_uri}, writing to path: {_filePath}");
_ = Task.Run(async () =>
{
await StartDownloadTask();
@ -40,6 +47,8 @@ namespace RdtClient.Service.Services.Downloaders
public Task Cancel()
{
_logger.Debug($"Cancelling download {_uri}");
_cancelled = true;
return Task.CompletedTask;

View file

@ -295,10 +295,10 @@ namespace RdtClient.Service.Services
foreach (var torrent in torrents)
{
// Check if there are any downloads that are queued and can be started.
var queuedDownloads = torrents.SelectMany(m => m.Downloads)
.Where(m => m.Completed == null && m.DownloadQueued != null && m.DownloadStarted == null && m.Error == null)
.OrderBy(m => m.DownloadQueued)
.ToList();
var queuedDownloads = torrent.Downloads
.Where(m => m.Completed == null && m.DownloadQueued != null && m.DownloadStarted == null && m.Error == null)
.OrderBy(m => m.DownloadQueued)
.ToList();
foreach (var download in queuedDownloads)
{
@ -374,10 +374,10 @@ namespace RdtClient.Service.Services
}
// Check if there are any unpacks that are queued and can be started.
var queuedUnpacks = torrents.SelectMany(m => m.Downloads)
.Where(m => m.Completed == null && m.UnpackingQueued != null && m.UnpackingStarted == null && m.Error == null)
.OrderBy(m => m.DownloadQueued)
.ToList();
var queuedUnpacks = torrent.Downloads
.Where(m => m.Completed == null && m.UnpackingQueued != null && m.UnpackingStarted == null && m.Error == null)
.OrderBy(m => m.DownloadQueued)
.ToList();
foreach (var download in queuedUnpacks)
{

View file

@ -4,7 +4,7 @@
<TargetFramework>net5.0</TargetFramework>
<OutputType>Exe</OutputType>
<UserSecretsId>94c24cba-f03f-4453-a671-3640b517c573</UserSecretsId>
<Version>1.9.1</Version>
<Version>1.9.2</Version>
</PropertyGroup>
<ItemGroup>