mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Test if the OutputPath specified by TvDirectory/TvCategory exists.
This commit is contained in:
parent
c56c83e169
commit
9304547c95
@ -23,20 +23,22 @@ public class TorrentDownloadStation : TorrentClientBase<DownloadStationSettings>
|
|||||||
protected readonly IDownloadStationProxy _proxy;
|
protected readonly IDownloadStationProxy _proxy;
|
||||||
protected readonly ISharedFolderResolver _sharedFolderResolver;
|
protected readonly ISharedFolderResolver _sharedFolderResolver;
|
||||||
protected readonly ISerialNumberProvider _serialNumberProvider;
|
protected readonly ISerialNumberProvider _serialNumberProvider;
|
||||||
|
protected readonly IFileStationProxy _fileStationProxy;
|
||||||
|
|
||||||
public TorrentDownloadStation(IDownloadStationProxy proxy,
|
public TorrentDownloadStation(ISharedFolderResolver sharedFolderResolver,
|
||||||
ITorrentFileInfoReader torrentFileInfoReader,
|
ISerialNumberProvider serialNumberProvider,
|
||||||
IHttpClient httpClient,
|
IFileStationProxy fileStationProxy,
|
||||||
IConfigService configService,
|
IDownloadStationProxy proxy,
|
||||||
IDiskProvider diskProvider,
|
ITorrentFileInfoReader torrentFileInfoReader,
|
||||||
IRemotePathMappingService remotePathMappingService,
|
IHttpClient httpClient,
|
||||||
Logger logger,
|
IConfigService configService,
|
||||||
ICacheManager cacheManager,
|
IDiskProvider diskProvider,
|
||||||
ISharedFolderResolver sharedFolderResolver,
|
IRemotePathMappingService remotePathMappingService,
|
||||||
ISerialNumberProvider serialNumberProvider)
|
Logger logger)
|
||||||
: base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger)
|
: base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger)
|
||||||
{
|
{
|
||||||
_proxy = proxy;
|
_proxy = proxy;
|
||||||
|
_fileStationProxy = fileStationProxy;
|
||||||
_sharedFolderResolver = sharedFolderResolver;
|
_sharedFolderResolver = sharedFolderResolver;
|
||||||
_serialNumberProvider = serialNumberProvider;
|
_serialNumberProvider = serialNumberProvider;
|
||||||
}
|
}
|
||||||
@ -181,57 +183,10 @@ protected override void Test(List<ValidationFailure> failures)
|
|||||||
{
|
{
|
||||||
failures.AddIfNotNull(TestConnection());
|
failures.AddIfNotNull(TestConnection());
|
||||||
if (failures.Any()) return;
|
if (failures.Any()) return;
|
||||||
|
failures.AddIfNotNull(TestOutputPath());
|
||||||
failures.AddIfNotNull(TestGetTorrents());
|
failures.AddIfNotNull(TestGetTorrents());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ValidationFailure TestConnection()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return ValidateVersion();
|
|
||||||
}
|
|
||||||
catch (DownloadClientAuthenticationException ex)
|
|
||||||
{
|
|
||||||
_logger.Error(ex, ex.Message);
|
|
||||||
return new NzbDroneValidationFailure("Username", "Authentication failure")
|
|
||||||
{
|
|
||||||
DetailedDescription = $"Please verify your username and password. Also verify if the host running Sonarr isn't blocked from accessing {Name} by WhiteList limitations in the {Name} configuration."
|
|
||||||
};
|
|
||||||
}
|
|
||||||
catch (WebException ex)
|
|
||||||
{
|
|
||||||
_logger.Error(ex);
|
|
||||||
|
|
||||||
if (ex.Status == WebExceptionStatus.ConnectFailure)
|
|
||||||
{
|
|
||||||
return new NzbDroneValidationFailure("Host", "Unable to connect")
|
|
||||||
{
|
|
||||||
DetailedDescription = "Please verify the hostname and port."
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return new NzbDroneValidationFailure(string.Empty, "Unknown exception: " + ex.Message);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.Error(ex);
|
|
||||||
return new NzbDroneValidationFailure(string.Empty, "Unknown exception: " + ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ValidationFailure ValidateVersion()
|
|
||||||
{
|
|
||||||
var versionRange = _proxy.GetApiVersion(Settings);
|
|
||||||
|
|
||||||
_logger.Debug("Download Station api version information: Min {0} - Max {1}", versionRange.Min(), versionRange.Max());
|
|
||||||
|
|
||||||
if (!versionRange.Contains(2))
|
|
||||||
{
|
|
||||||
return new ValidationFailure(string.Empty, $"Download Station API version not supported, should be at least 2. It supports from {versionRange.Min()} to {versionRange.Max()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected bool IsFinished(DownloadStationTask torrent)
|
protected bool IsFinished(DownloadStationTask torrent)
|
||||||
{
|
{
|
||||||
return torrent.Status == DownloadStationTaskStatus.Finished;
|
return torrent.Status == DownloadStationTaskStatus.Finished;
|
||||||
@ -308,6 +263,93 @@ protected long GetRemainingSize(DownloadStationTask torrent)
|
|||||||
return TimeSpan.FromSeconds(remainingSize / downloadSpeed);
|
return TimeSpan.FromSeconds(remainingSize / downloadSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ValidationFailure TestOutputPath()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var downloadDir = GetDownloadDirectory();
|
||||||
|
|
||||||
|
if (downloadDir != null)
|
||||||
|
{
|
||||||
|
var sharedFolder = downloadDir.Split('\\', '/')[0];
|
||||||
|
var fieldName = Settings.TvDirectory.IsNotNullOrWhiteSpace() ? nameof(Settings.TvDirectory) : nameof(Settings.TvCategory);
|
||||||
|
|
||||||
|
var folderInfo = _fileStationProxy.GetInfoFileOrDirectory($"/{downloadDir}", Settings);
|
||||||
|
|
||||||
|
if (folderInfo.Additional == null)
|
||||||
|
{
|
||||||
|
return new NzbDroneValidationFailure(fieldName, $"Shared folder does not exist")
|
||||||
|
{
|
||||||
|
DetailedDescription = $"The DownloadStation does not have a Shared Folder with the name '{sharedFolder}', are you sure you specified it correctly?"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!folderInfo.IsDir)
|
||||||
|
{
|
||||||
|
return new NzbDroneValidationFailure(fieldName, $"Folder does not exist")
|
||||||
|
{
|
||||||
|
DetailedDescription = $"The folder '{downloadDir}' does not exist, it must be created manually inside the inside the Shared Folder '{sharedFolder}'."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex);
|
||||||
|
return new NzbDroneValidationFailure(string.Empty, $"Unknown exception: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ValidationFailure TestConnection()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ValidateVersion();
|
||||||
|
}
|
||||||
|
catch (DownloadClientAuthenticationException ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex, ex.Message);
|
||||||
|
return new NzbDroneValidationFailure("Username", "Authentication failure")
|
||||||
|
{
|
||||||
|
DetailedDescription = $"Please verify your username and password. Also verify if the host running Sonarr isn't blocked from accessing {Name} by WhiteList limitations in the {Name} configuration."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (WebException ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex);
|
||||||
|
|
||||||
|
if (ex.Status == WebExceptionStatus.ConnectFailure)
|
||||||
|
{
|
||||||
|
return new NzbDroneValidationFailure("Host", "Unable to connect")
|
||||||
|
{
|
||||||
|
DetailedDescription = "Please verify the hostname and port."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return new NzbDroneValidationFailure(string.Empty, $"Unknown exception: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex);
|
||||||
|
return new NzbDroneValidationFailure(string.Empty, $"Unknown exception: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ValidationFailure ValidateVersion()
|
||||||
|
{
|
||||||
|
var versionRange = _proxy.GetApiVersion(Settings);
|
||||||
|
|
||||||
|
_logger.Debug("Download Station api version information: Min {0} - Max {1}", versionRange.Min(), versionRange.Max());
|
||||||
|
|
||||||
|
if (!versionRange.Contains(2))
|
||||||
|
{
|
||||||
|
return new ValidationFailure(string.Empty, $"Download Station API version not supported, should be at least 2. It supports from {versionRange.Min()} to {versionRange.Max()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
protected ValidationFailure TestGetTorrents()
|
protected ValidationFailure TestGetTorrents()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -317,7 +359,7 @@ protected ValidationFailure TestGetTorrents()
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return new NzbDroneValidationFailure(string.Empty, "Failed to get the list of torrents: " + ex.Message);
|
return new NzbDroneValidationFailure(string.Empty, $"Failed to get the list of torrents: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,18 +20,22 @@ public class UsenetDownloadStation : UsenetClientBase<DownloadStationSettings>
|
|||||||
protected readonly IDownloadStationProxy _proxy;
|
protected readonly IDownloadStationProxy _proxy;
|
||||||
protected readonly ISharedFolderResolver _sharedFolderResolver;
|
protected readonly ISharedFolderResolver _sharedFolderResolver;
|
||||||
protected readonly ISerialNumberProvider _serialNumberProvider;
|
protected readonly ISerialNumberProvider _serialNumberProvider;
|
||||||
|
protected readonly IFileStationProxy _fileStationProxy;
|
||||||
|
|
||||||
public UsenetDownloadStation(IDownloadStationProxy proxy,
|
public UsenetDownloadStation(ISharedFolderResolver sharedFolderResolver,
|
||||||
|
ISerialNumberProvider serialNumberProvider,
|
||||||
|
IFileStationProxy fileStationProxy,
|
||||||
|
IDownloadStationProxy proxy,
|
||||||
IHttpClient httpClient,
|
IHttpClient httpClient,
|
||||||
IConfigService configService,
|
IConfigService configService,
|
||||||
IDiskProvider diskProvider,
|
IDiskProvider diskProvider,
|
||||||
IRemotePathMappingService remotePathMappingService,
|
IRemotePathMappingService remotePathMappingService,
|
||||||
Logger logger,
|
Logger logger
|
||||||
ISharedFolderResolver sharedFolderResolver,
|
)
|
||||||
ISerialNumberProvider serialNumberProvider)
|
|
||||||
: base(httpClient, configService, diskProvider, remotePathMappingService, logger)
|
: base(httpClient, configService, diskProvider, remotePathMappingService, logger)
|
||||||
{
|
{
|
||||||
_proxy = proxy;
|
_proxy = proxy;
|
||||||
|
_fileStationProxy = fileStationProxy;
|
||||||
_sharedFolderResolver = sharedFolderResolver;
|
_sharedFolderResolver = sharedFolderResolver;
|
||||||
_serialNumberProvider = serialNumberProvider;
|
_serialNumberProvider = serialNumberProvider;
|
||||||
}
|
}
|
||||||
@ -173,9 +177,49 @@ protected override void Test(List<ValidationFailure> failures)
|
|||||||
{
|
{
|
||||||
failures.AddIfNotNull(TestConnection());
|
failures.AddIfNotNull(TestConnection());
|
||||||
if (failures.Any()) return;
|
if (failures.Any()) return;
|
||||||
|
failures.AddIfNotNull(TestOutputPath());
|
||||||
failures.AddIfNotNull(TestGetNZB());
|
failures.AddIfNotNull(TestGetNZB());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ValidationFailure TestOutputPath()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var downloadDir = GetDownloadDirectory();
|
||||||
|
|
||||||
|
if (downloadDir != null)
|
||||||
|
{
|
||||||
|
var sharedFolder = downloadDir.Split('\\', '/')[0];
|
||||||
|
var fieldName = Settings.TvDirectory.IsNotNullOrWhiteSpace() ? nameof(Settings.TvDirectory) : nameof(Settings.TvCategory);
|
||||||
|
|
||||||
|
var folderInfo = _fileStationProxy.GetInfoFileOrDirectory($"/{downloadDir}", Settings);
|
||||||
|
|
||||||
|
if (folderInfo.Additional == null)
|
||||||
|
{
|
||||||
|
return new NzbDroneValidationFailure(fieldName, $"Shared folder does not exist")
|
||||||
|
{
|
||||||
|
DetailedDescription = $"The DownloadStation does not have a Shared Folder with the name '{sharedFolder}', are you sure you specified it correctly?"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!folderInfo.IsDir)
|
||||||
|
{
|
||||||
|
return new NzbDroneValidationFailure(fieldName, $"Folder does not exist")
|
||||||
|
{
|
||||||
|
DetailedDescription = $"The folder '{downloadDir}' does not exist, it must be created manually inside the inside the Shared Folder '{sharedFolder}'."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex);
|
||||||
|
return new NzbDroneValidationFailure(string.Empty, $"Unknown exception: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected ValidationFailure TestConnection()
|
protected ValidationFailure TestConnection()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
Loading…
Reference in New Issue
Block a user