From 03997e2a0d3c1418ed4723d839385e5a3fbf000f Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sun, 29 Apr 2018 13:05:43 +0200 Subject: [PATCH] Switched to BigInteger for qbit eta as workaround for api bug, tyvm. --- src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 1 + .../Download/Clients/QBittorrent/QBittorrent.cs | 12 +++++++++++- .../Clients/QBittorrent/QBittorrentTorrent.cs | 5 +++-- src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 5832ba9a4..c7085eb48 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -98,6 +98,7 @@ + diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs index 56ff9f315..664809cdc 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs @@ -107,7 +107,7 @@ public override IEnumerable GetItems() item.TotalSize = torrent.Size; item.DownloadClient = Definition.Name; item.RemainingSize = (long)(torrent.Size * (1.0 - torrent.Progress)); - item.RemainingTime = TimeSpan.FromSeconds(torrent.Eta); + item.RemainingTime = GetRemainingTime(torrent); item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.SavePath)); @@ -333,5 +333,15 @@ private void SetInitialState(string hash) _logger.Warn(ex, "Failed to set inital state for {0}.", hash); } } + + protected TimeSpan? GetRemainingTime(QBittorrentTorrent torrent) + { + if (torrent.Eta < 0 || torrent.Eta > 365 * 24 * 3600) + { + return null; + } + + return TimeSpan.FromSeconds((int)torrent.Eta); + } } } diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentTorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentTorrent.cs index 266d22f95..d5fa0b5e7 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentTorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentTorrent.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System.Numerics; +using Newtonsoft.Json; namespace NzbDrone.Core.Download.Clients.QBittorrent { @@ -13,7 +14,7 @@ public class QBittorrentTorrent public double Progress { get; set; } // Torrent progress (%/100) - public ulong Eta { get; set; } // Torrent ETA (seconds) + public BigInteger Eta { get; set; } // Torrent ETA (seconds) (QBit contains a bug exceeding ulong limits) public string State { get; set; } // Torrent state. See possible values here below diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 555710344..e278fa376 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -98,6 +98,7 @@ +