public override IEnumerable <DownloadClientItem> GetItems() { var items = new List <DownloadClientItem>(); var list = _proxy.GetTorrents(Settings); foreach (var torrent in list) { var properties = torrent.Value; if (!Settings.Tags.All(tag => properties.Tags.Contains(tag))) { continue; } var item = new DownloadClientItem { DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this), DownloadId = torrent.Key, Title = properties.Name, OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(properties.Directory)), Category = properties.Tags.Count > 0 ? properties.Tags[0] : null, RemainingSize = properties.SizeBytes - properties.BytesDone, TotalSize = properties.SizeBytes, SeedRatio = properties.Ratio, Message = properties.Message, CanMoveFiles = false, CanBeRemoved = false, }; if (properties.Eta > 0) { item.RemainingTime = TimeSpan.FromSeconds(properties.Eta); } if (properties.Status.Contains("error")) { item.Status = DownloadItemStatus.Warning; } else if (properties.Status.Contains("seeding") || properties.Status.Contains("complete")) { item.Status = DownloadItemStatus.Completed; } else if (properties.Status.Contains("downloading")) { item.Status = DownloadItemStatus.Downloading; } else if (properties.Status.Contains("stopped")) { item.Status = DownloadItemStatus.Paused; } if (item.Status == DownloadItemStatus.Completed) { // Grab cached seedConfig var seedConfig = _downloadSeedConfigProvider.GetSeedConfiguration(item.DownloadId); if (seedConfig != null) { if (item.SeedRatio >= seedConfig.Ratio) { // Check if seed ratio reached item.CanMoveFiles = item.CanBeRemoved = true; } else if (properties.DateFinished != null && properties.DateFinished > 0) { // Check if seed time reached if ((DateTimeOffset.Now - DateTimeOffset.FromUnixTimeSeconds((long)properties.DateFinished)) >= seedConfig.SeedTime) { item.CanMoveFiles = item.CanBeRemoved = true; } } } } items.Add(item); } return(items); }
public override IEnumerable <DownloadClientItem> GetItems() { var torrents = _proxy.GetTorrents(Settings); _logger.Debug("Retrieved metadata of {0} torrents in client", torrents.Count); var items = new List <DownloadClientItem>(); foreach (RTorrentTorrent torrent in torrents) { // Don't concern ourselves with categories other than specified if (Settings.TvCategory.IsNotNullOrWhiteSpace() && torrent.Category != Settings.TvCategory) { continue; } if (torrent.Path.StartsWith(".")) { throw new DownloadClientException("Download paths must be absolute. Please specify variable \"directory\" in rTorrent."); } var item = new DownloadClientItem(); item.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this); item.Title = torrent.Name; item.DownloadId = torrent.Hash; item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.Path)); item.TotalSize = torrent.TotalSize; item.RemainingSize = torrent.RemainingSize; item.Category = torrent.Category; item.SeedRatio = torrent.Ratio; if (torrent.DownRate > 0) { var secondsLeft = torrent.RemainingSize / torrent.DownRate; item.RemainingTime = TimeSpan.FromSeconds(secondsLeft); } else { item.RemainingTime = TimeSpan.Zero; } if (torrent.IsFinished) { item.Status = DownloadItemStatus.Completed; } else if (torrent.IsActive) { item.Status = DownloadItemStatus.Downloading; } else if (!torrent.IsActive) { item.Status = DownloadItemStatus.Paused; } // Grab cached seedConfig var seedConfig = _downloadSeedConfigProvider.GetSeedConfiguration(torrent.Hash); // Check if torrent is finished and if it exceeds cached seedConfig item.CanMoveFiles = item.CanBeRemoved = torrent.IsFinished && seedConfig != null && ( (torrent.Ratio / 1000.0) >= seedConfig.Ratio || (DateTimeOffset.Now - DateTimeOffset.FromUnixTimeSeconds(torrent.FinishedTime)) >= seedConfig.SeedTime ); items.Add(item); } return(items); }