|
|
@ -1,18 +1,18 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
|
|
using FluentValidation.Results;
|
|
|
|
|
|
|
|
using NLog;
|
|
|
|
|
|
|
|
using NzbDrone.Common.Cache;
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
using NzbDrone.Common.Http;
|
|
|
|
using NzbDrone.Common.Http;
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
using NzbDrone.Core.MediaFiles.TorrentInfo;
|
|
|
|
using NzbDrone.Core.MediaFiles.TorrentInfo;
|
|
|
|
using NLog;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Validation;
|
|
|
|
using NzbDrone.Core.Validation;
|
|
|
|
using FluentValidation.Results;
|
|
|
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
using NzbDrone.Core.RemotePathMappings;
|
|
|
|
using NzbDrone.Core.RemotePathMappings;
|
|
|
|
using NzbDrone.Common.Cache;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Download.Clients.QBittorrent
|
|
|
|
namespace NzbDrone.Core.Download.Clients.QBittorrent
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -122,6 +122,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
|
|
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<DownloadClientItem> GetItems()
|
|
|
|
public override IEnumerable<DownloadClientItem> GetItems()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var version = Proxy.GetApiVersion(Settings);
|
|
|
|
var config = Proxy.GetConfig(Settings);
|
|
|
|
var config = Proxy.GetConfig(Settings);
|
|
|
|
var torrents = Proxy.GetTorrents(Settings);
|
|
|
|
var torrents = Proxy.GetTorrents(Settings);
|
|
|
|
|
|
|
|
|
|
|
@ -138,19 +139,18 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
|
|
|
|
DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
|
|
|
|
DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
|
|
|
|
RemainingSize = (long)(torrent.Size * (1.0 - torrent.Progress)),
|
|
|
|
RemainingSize = (long)(torrent.Size * (1.0 - torrent.Progress)),
|
|
|
|
RemainingTime = GetRemainingTime(torrent),
|
|
|
|
RemainingTime = GetRemainingTime(torrent),
|
|
|
|
SeedRatio = torrent.Ratio,
|
|
|
|
SeedRatio = torrent.Ratio
|
|
|
|
OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.SavePath)),
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (version >= new Version("2.6.1"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.ContentPath));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Avoid removing torrents that haven't reached the global max ratio.
|
|
|
|
// Avoid removing torrents that haven't reached the global max ratio.
|
|
|
|
// Removal also requires the torrent to be paused, in case a higher max ratio was set on the torrent itself (which is not exposed by the api).
|
|
|
|
// Removal also requires the torrent to be paused, in case a higher max ratio was set on the torrent itself (which is not exposed by the api).
|
|
|
|
item.CanMoveFiles = item.CanBeRemoved = (torrent.State == "pausedUP" && HasReachedSeedLimit(torrent, config));
|
|
|
|
item.CanMoveFiles = item.CanBeRemoved = (torrent.State == "pausedUP" && HasReachedSeedLimit(torrent, config));
|
|
|
|
|
|
|
|
|
|
|
|
if (!item.OutputPath.IsEmpty && item.OutputPath.FileName != torrent.Name)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
item.OutputPath += torrent.Name;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (torrent.State)
|
|
|
|
switch (torrent.State)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case "error": // some error occurred, applies to paused torrents
|
|
|
|
case "error": // some error occurred, applies to paused torrents
|
|
|
@ -218,6 +218,49 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
|
|
|
|
Proxy.RemoveTorrent(hash.ToLower(), deleteData, Settings);
|
|
|
|
Proxy.RemoveTorrent(hash.ToLower(), deleteData, Settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// On API version >= 2.6.1 this is already set correctly
|
|
|
|
|
|
|
|
if (!item.OutputPath.IsEmpty)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var files = Proxy.GetTorrentFiles(item.DownloadId.ToLower(), Settings);
|
|
|
|
|
|
|
|
if (!files.Any())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Debug($"No files found for torrent {item.Title} in qBittorrent");
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var properties = Proxy.GetTorrentProperties(item.DownloadId.ToLower(), Settings);
|
|
|
|
|
|
|
|
var savePath = new OsPath(properties.SavePath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = item.Clone();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OsPath outputPath;
|
|
|
|
|
|
|
|
if (files.Count == 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
outputPath = savePath + files[0].Name;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// we have multiple files in the torrent so just get
|
|
|
|
|
|
|
|
// the first subdirectory
|
|
|
|
|
|
|
|
var relativePath = new OsPath(files[0].Name);
|
|
|
|
|
|
|
|
while (!relativePath.Directory.IsEmpty)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
relativePath = relativePath.Directory;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
outputPath = savePath + relativePath;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, outputPath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override DownloadClientInfo GetStatus()
|
|
|
|
public override DownloadClientInfo GetStatus()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var config = Proxy.GetConfig(Settings);
|
|
|
|
var config = Proxy.GetConfig(Settings);
|
|
|
|