Skip to content

Commit

Permalink
Add some error handling for calculating progress for qBittorrent.
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerfar committed Jun 3, 2024
1 parent 2bf1c99 commit 86eaccd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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).

## [2.0.79] - 2024-06-03
### Changed
- Fixed issue with qBittorrent progress sometimes throwing errors.

## [2.0.78] - 2024-05-04
### Changed
- Fixed Aria2c download path issue when a category is set.
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/navbar/navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<a class="navbar-item" routerLink="profile"> Profile </a>
<a class="navbar-item" (click)="logout()"> Logout </a>
<hr class="navbar-divider" />
<a href="https://github.com/rogerfar/rdt-client" target="_blank" class="navbar-item">Version 2.0.78</a>
<a href="https://github.com/rogerfar/rdt-client" target="_blank" class="navbar-item">Version 2.0.79</a>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rdt-client",
"version": "2.0.78",
"version": "2.0.79",
"description": "This is a web interface to manage your torrents on Real-Debrid.",
"main": "index.js",
"dependencies": {
Expand Down
28 changes: 22 additions & 6 deletions server/RdtClient.Service/Services/QBittorrent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,36 @@ public async Task<IList<TorrentInfo>> TorrentInfo()
torrentPath = Path.Combine(downloadPath, torrent.RdName) + Path.DirectorySeparatorChar;
}

var rdProgress = (torrent.RdProgress ?? 0) / 100.0m;
var bytesTotal = torrent.RdSize ?? 1;
var bytesDone = (Int64)(bytesTotal * rdProgress);
var speed = torrent.RdSpeed ?? 0;
Int64 bytesDone = 0;
Int64 bytesTotal = 0;
Int64 speed = 0;
Int64 rdProgress = 0;
try
{
rdProgress = (Int64) ((torrent.RdProgress ?? 0) / 100.0m);
bytesTotal = torrent.RdSize ?? 1;
bytesDone = bytesTotal * rdProgress;
speed = torrent.RdSpeed ?? 0;
}
catch (Exception ex)
{
logger.LogError(ex, $"""
Error calculating progress:
RdProgress: {torrent.RdProgress}
RdSize: {torrent.RdSize}
RdSpeed: {torrent.RdSpeed}
""");
}

if (torrent.Downloads.Count > 0)
{
bytesDone = torrent.Downloads.Sum(m => m.BytesDone);
bytesTotal = torrent.Downloads.Sum(m => m.BytesTotal);
speed = (Int32) torrent.Downloads.Average(m => m.Speed);
downloadProgress = bytesTotal > 0 ? (Decimal)bytesDone / bytesTotal : 0;
downloadProgress = bytesTotal > 0 ? (Decimal) bytesDone / bytesTotal : 0;
}

var progress = (rdProgress + downloadProgress) / 2m;
var progress = (Int64) ((rdProgress + downloadProgress) / 2m);

var result = new TorrentInfo
{
Expand Down
2 changes: 1 addition & 1 deletion server/RdtClient.Web/RdtClient.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<UserSecretsId>94c24cba-f03f-4453-a671-3640b517c573</UserSecretsId>
<Version>2.0.78</Version>
<Version>2.0.79</Version>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
Expand Down

0 comments on commit 86eaccd

Please sign in to comment.