|
|
@ -12,14 +12,17 @@ using FluentValidation.Results;
|
|
|
|
using System.Net;
|
|
|
|
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.UTorrent
|
|
|
|
namespace NzbDrone.Core.Download.Clients.UTorrent
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class UTorrent : TorrentClientBase<UTorrentSettings>
|
|
|
|
public class UTorrent : TorrentClientBase<UTorrentSettings>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IUTorrentProxy _proxy;
|
|
|
|
private readonly IUTorrentProxy _proxy;
|
|
|
|
|
|
|
|
private readonly ICached<UTorrentTorrentCache> _torrentCache;
|
|
|
|
|
|
|
|
|
|
|
|
public UTorrent(IUTorrentProxy proxy,
|
|
|
|
public UTorrent(IUTorrentProxy proxy,
|
|
|
|
|
|
|
|
ICacheManager cacheManager,
|
|
|
|
ITorrentFileInfoReader torrentFileInfoReader,
|
|
|
|
ITorrentFileInfoReader torrentFileInfoReader,
|
|
|
|
IHttpClient httpClient,
|
|
|
|
IHttpClient httpClient,
|
|
|
|
IConfigService configService,
|
|
|
|
IConfigService configService,
|
|
|
@ -29,6 +32,8 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
|
|
|
|
: base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger)
|
|
|
|
: base(torrentFileInfoReader, httpClient, configService, diskProvider, remotePathMappingService, logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_proxy = proxy;
|
|
|
|
_proxy = proxy;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_torrentCache = cacheManager.GetCache<UTorrentTorrentCache>(GetType(), "differentialTorrents");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override string AddFromMagnetLink(RemoteEpisode remoteEpisode, string hash, string magnetLink)
|
|
|
|
protected override string AddFromMagnetLink(RemoteEpisode remoteEpisode, string hash, string magnetLink)
|
|
|
@ -77,7 +82,32 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
torrents = _proxy.GetTorrents(Settings);
|
|
|
|
var cacheKey = string.Format("{0}:{1}:{2}", Settings.Host, Settings.Port, Settings.TvCategory);
|
|
|
|
|
|
|
|
var cache = _torrentCache.Find(cacheKey);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var response = _proxy.GetTorrents(cache == null ? null : cache.CacheID, Settings);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cache != null && response.Torrents == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var removedAndUpdated = new HashSet<string>(response.TorrentsChanged.Select(v => v.Hash).Concat(response.TorrentsRemoved));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
torrents = cache.Torrents
|
|
|
|
|
|
|
|
.Where(v => !removedAndUpdated.Contains(v.Hash))
|
|
|
|
|
|
|
|
.Concat(response.TorrentsChanged)
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
torrents = response.Torrents;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cache = new UTorrentTorrentCache
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CacheID = response.CacheNumber,
|
|
|
|
|
|
|
|
Torrents = torrents
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_torrentCache.Set(cacheKey, cache, TimeSpan.FromMinutes(15));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (DownloadClientException ex)
|
|
|
|
catch (DownloadClientException ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -239,7 +269,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_proxy.GetTorrents(Settings);
|
|
|
|
_proxy.GetTorrents(null, Settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|