1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2025-01-03 05:35:29 +00:00

Deluge communication improvements

Closes #7318
This commit is contained in:
Mark McDowall 2024-11-26 17:36:53 -08:00 committed by GitHub
parent 12c1eb86f2
commit 183b8b574a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 44 deletions

View file

@ -20,6 +20,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge
public class Deluge : TorrentClientBase<DelugeSettings> public class Deluge : TorrentClientBase<DelugeSettings>
{ {
private readonly IDelugeProxy _proxy; private readonly IDelugeProxy _proxy;
private bool _hasAttemptedReconnecting;
public Deluge(IDelugeProxy proxy, public Deluge(IDelugeProxy proxy,
ITorrentFileInfoReader torrentFileInfoReader, ITorrentFileInfoReader torrentFileInfoReader,
@ -128,14 +129,9 @@ namespace NzbDrone.Core.Download.Clients.Deluge
foreach (var torrent in torrents) foreach (var torrent in torrents)
{ {
// Silently ignore torrents with no hash // Ignore torrents without a hash or name, but track to log a single warning
if (torrent.Hash.IsNullOrWhiteSpace()) // for all invalid torrents as well as reconnect to the Daemon.
{ if (torrent.Hash.IsNullOrWhiteSpace() || torrent.Name.IsNullOrWhiteSpace())
continue;
}
// Ignore torrents without a name, but track to log a single warning for all invalid torrents.
if (torrent.Name.IsNullOrWhiteSpace())
{ {
ignoredCount++; ignoredCount++;
continue; continue;
@ -199,9 +195,20 @@ namespace NzbDrone.Core.Download.Clients.Deluge
items.Add(item); items.Add(item);
} }
if (ignoredCount > 0) if (ignoredCount > 0 && _hasAttemptedReconnecting)
{ {
_logger.Warn("{0} torrent(s) were ignored because they did not have a title. Check Deluge and remove any invalid torrents"); if (_hasAttemptedReconnecting)
{
_logger.Warn("{0} torrent(s) were ignored because they did not have a hash or title. Deluge may have disconnected from it's daemon. If you continue to see this error, check Deluge for invalid torrents.", ignoredCount);
}
else
{
_proxy.ReconnectToDaemon(Settings);
}
}
else
{
_hasAttemptedReconnecting = false;
} }
return items; return items;
@ -322,9 +329,9 @@ namespace NzbDrone.Core.Download.Clients.Deluge
return null; return null;
} }
var enabledPlugins = _proxy.GetEnabledPlugins(Settings); var methods = _proxy.GetMethods(Settings);
if (!enabledPlugins.Contains("Label")) if (!methods.Any(m => m.StartsWith("label.")))
{ {
return new NzbDroneValidationFailure("TvCategory", _localizationService.GetLocalizedString("DownloadClientDelugeValidationLabelPluginInactive")) return new NzbDroneValidationFailure("TvCategory", _localizationService.GetLocalizedString("DownloadClientDelugeValidationLabelPluginInactive"))
{ {

View file

@ -18,8 +18,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge
Dictionary<string, object> GetConfig(DelugeSettings settings); Dictionary<string, object> GetConfig(DelugeSettings settings);
DelugeTorrent[] GetTorrents(DelugeSettings settings); DelugeTorrent[] GetTorrents(DelugeSettings settings);
DelugeTorrent[] GetTorrentsByLabel(string label, DelugeSettings settings); DelugeTorrent[] GetTorrentsByLabel(string label, DelugeSettings settings);
string[] GetAvailablePlugins(DelugeSettings settings); string[] GetMethods(DelugeSettings settings);
string[] GetEnabledPlugins(DelugeSettings settings);
string[] GetAvailableLabels(DelugeSettings settings); string[] GetAvailableLabels(DelugeSettings settings);
DelugeLabel GetLabelOptions(DelugeSettings settings); DelugeLabel GetLabelOptions(DelugeSettings settings);
void SetTorrentLabel(string hash, string label, DelugeSettings settings); void SetTorrentLabel(string hash, string label, DelugeSettings settings);
@ -30,6 +29,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge
string AddTorrentFromFile(string filename, byte[] fileContent, DelugeSettings settings); string AddTorrentFromFile(string filename, byte[] fileContent, DelugeSettings settings);
bool RemoveTorrent(string hash, bool removeData, DelugeSettings settings); bool RemoveTorrent(string hash, bool removeData, DelugeSettings settings);
void MoveTorrentToTopInQueue(string hash, DelugeSettings settings); void MoveTorrentToTopInQueue(string hash, DelugeSettings settings);
void ReconnectToDaemon(DelugeSettings settings);
} }
public class DelugeProxy : IDelugeProxy public class DelugeProxy : IDelugeProxy
@ -51,25 +51,14 @@ namespace NzbDrone.Core.Download.Clients.Deluge
public string GetVersion(DelugeSettings settings) public string GetVersion(DelugeSettings settings)
{ {
try var methods = GetMethods(settings);
if (methods.Contains("daemon.get_version"))
{ {
var response = ProcessRequest<string>(settings, "daemon.info"); return ProcessRequest<string>(settings, "daemon.get_version");
return response;
} }
catch (DownloadClientException ex)
{
if (ex.Message.Contains("Unknown method"))
{
// Deluge v2 beta replaced 'daemon.info' with 'daemon.get_version'.
// It may return or become official, for now we just retry with the get_version api.
var response = ProcessRequest<string>(settings, "daemon.get_version");
return response; return ProcessRequest<string>(settings, "daemon.info");
}
throw;
}
} }
public Dictionary<string, object> GetConfig(DelugeSettings settings) public Dictionary<string, object> GetConfig(DelugeSettings settings)
@ -101,6 +90,13 @@ namespace NzbDrone.Core.Download.Clients.Deluge
return GetTorrents(response); return GetTorrents(response);
} }
public string[] GetMethods(DelugeSettings settings)
{
var response = ProcessRequest<string[]>(settings, "system.listMethods");
return response;
}
public string AddTorrentFromMagnet(string magnetLink, DelugeSettings settings) public string AddTorrentFromMagnet(string magnetLink, DelugeSettings settings)
{ {
dynamic options = new ExpandoObject(); dynamic options = new ExpandoObject();
@ -159,20 +155,6 @@ namespace NzbDrone.Core.Download.Clients.Deluge
ProcessRequest<object>(settings, "core.queue_top", (object)new string[] { hash }); ProcessRequest<object>(settings, "core.queue_top", (object)new string[] { hash });
} }
public string[] GetAvailablePlugins(DelugeSettings settings)
{
var response = ProcessRequest<string[]>(settings, "core.get_available_plugins");
return response;
}
public string[] GetEnabledPlugins(DelugeSettings settings)
{
var response = ProcessRequest<string[]>(settings, "core.get_enabled_plugins");
return response;
}
public string[] GetAvailableLabels(DelugeSettings settings) public string[] GetAvailableLabels(DelugeSettings settings)
{ {
var response = ProcessRequest<string[]>(settings, "label.get_labels"); var response = ProcessRequest<string[]>(settings, "label.get_labels");
@ -223,6 +205,12 @@ namespace NzbDrone.Core.Download.Clients.Deluge
ProcessRequest<object>(settings, "label.set_torrent", hash, label); ProcessRequest<object>(settings, "label.set_torrent", hash, label);
} }
public void ReconnectToDaemon(DelugeSettings settings)
{
ProcessRequest<string>(settings, "web.disconnect");
ConnectDaemon(BuildRequest(settings));
}
private JsonRpcRequestBuilder BuildRequest(DelugeSettings settings) private JsonRpcRequestBuilder BuildRequest(DelugeSettings settings)
{ {
var url = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, settings.UrlBase); var url = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, settings.UrlBase);