示例#1
0
文件: Flood.cs 项目: lanicon/Readarr
        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,
                };

                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;
                }

                item.CanMoveFiles = item.CanBeRemoved = false;

                items.Add(item);
            }

            return(items);
        }
示例#2
0
文件: Nzbget.cs 项目: Animarr/Animarr
        private IEnumerable <DownloadClientItem> GetQueue()
        {
            var globalStatus = _proxy.GetGlobalStatus(Settings);
            var queue        = _proxy.GetQueue(Settings);

            var queueItems = new List <DownloadClientItem>();

            long totalRemainingSize = 0;

            foreach (var item in queue)
            {
                var totalSize     = MakeInt64(item.FileSizeHi, item.FileSizeLo);
                var pausedSize    = MakeInt64(item.PausedSizeHi, item.PausedSizeLo);
                var remainingSize = MakeInt64(item.RemainingSizeHi, item.RemainingSizeLo);

                var droneParameter = item.Parameters.SingleOrDefault(p => p.Name == "drone");

                var queueItem = new DownloadClientItem();
                queueItem.DownloadId = droneParameter == null?item.NzbId.ToString() : droneParameter.Value.ToString();

                queueItem.Title              = item.NzbName;
                queueItem.TotalSize          = totalSize;
                queueItem.Category           = item.Category;
                queueItem.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);
                queueItem.CanMoveFiles       = true;
                queueItem.CanBeRemoved       = true;

                if (globalStatus.DownloadPaused || (remainingSize == pausedSize && remainingSize != 0))
                {
                    queueItem.Status        = DownloadItemStatus.Paused;
                    queueItem.RemainingSize = remainingSize;
                }
                else
                {
                    if (item.ActiveDownloads == 0 && remainingSize != 0)
                    {
                        queueItem.Status = DownloadItemStatus.Queued;
                    }
                    else
                    {
                        queueItem.Status = DownloadItemStatus.Downloading;
                    }

                    queueItem.RemainingSize = remainingSize - pausedSize;

                    if (globalStatus.DownloadRate != 0)
                    {
                        queueItem.RemainingTime = TimeSpan.FromSeconds((totalRemainingSize + queueItem.RemainingSize) / globalStatus.DownloadRate);
                        totalRemainingSize     += queueItem.RemainingSize;
                    }
                }

                queueItems.Add(queueItem);
            }

            return(queueItems);
        }
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            var torrents     = GetTasks();
            var serialNumber = _serialNumberProvider.GetSerialNumber(Settings);

            var items = new List <DownloadClientItem>();

            foreach (var torrent in torrents)
            {
                var outputPath = new OsPath($"/{torrent.Additional.Detail["destination"]}");

                if (Settings.TvDirectory.IsNotNullOrWhiteSpace())
                {
                    if (!new OsPath($"/{Settings.TvDirectory}").Contains(outputPath))
                    {
                        continue;
                    }
                }
                else if (Settings.MusicCategory.IsNotNullOrWhiteSpace())
                {
                    var directories = outputPath.FullPath.Split('\\', '/');
                    if (!directories.Contains(Settings.MusicCategory))
                    {
                        continue;
                    }
                }

                var item = new DownloadClientItem()
                {
                    Category           = Settings.MusicCategory,
                    DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
                    DownloadId         = CreateDownloadId(torrent.Id, serialNumber),
                    Title         = torrent.Title,
                    TotalSize     = torrent.Size,
                    RemainingSize = GetRemainingSize(torrent),
                    RemainingTime = GetRemainingTime(torrent),
                    SeedRatio     = GetSeedRatio(torrent),
                    Status        = GetStatus(torrent),
                    Message       = GetMessage(torrent),
                    CanMoveFiles  = IsCompleted(torrent),
                    CanBeRemoved  = IsFinished(torrent)
                };

                if (item.Status == DownloadItemStatus.Completed || item.Status == DownloadItemStatus.Failed)
                {
                    item.OutputPath = GetOutputPath(outputPath, torrent, serialNumber);
                }

                items.Add(item);
            }

            return(items);
        }
示例#4
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            var queue = _proxy.GetQueue(Settings);

            foreach (var item in queue)
            {
                item.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);
                item.OutputPath         = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, item.OutputPath);
            }

            return(queue);
        }
示例#5
0
        private IEnumerable <DownloadClientItem> GetQueue()
        {
            var sabQueue   = _proxy.GetQueue(0, 0, Settings);
            var queueItems = new List <DownloadClientItem>();

            foreach (var sabQueueItem in sabQueue.Items)
            {
                if (sabQueueItem.Status == SabnzbdDownloadStatus.Deleted)
                {
                    continue;
                }

                var queueItem = new DownloadClientItem();
                queueItem.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);
                queueItem.DownloadId         = sabQueueItem.Id;
                queueItem.Category           = sabQueueItem.Category;
                queueItem.Title         = sabQueueItem.Title;
                queueItem.TotalSize     = (long)(sabQueueItem.Size * 1024 * 1024);
                queueItem.RemainingSize = (long)(sabQueueItem.Sizeleft * 1024 * 1024);
                queueItem.RemainingTime = sabQueueItem.Timeleft;
                queueItem.CanBeRemoved  = true;
                queueItem.CanMoveFiles  = true;

                if ((sabQueue.Paused && sabQueueItem.Priority != SabnzbdPriority.Force) ||
                    sabQueueItem.Status == SabnzbdDownloadStatus.Paused)
                {
                    queueItem.Status = DownloadItemStatus.Paused;

                    queueItem.RemainingTime = null;
                }
                else if (sabQueueItem.Status == SabnzbdDownloadStatus.Queued ||
                         sabQueueItem.Status == SabnzbdDownloadStatus.Grabbing ||
                         sabQueueItem.Status == SabnzbdDownloadStatus.Propagating)
                {
                    queueItem.Status = DownloadItemStatus.Queued;
                }
                else
                {
                    queueItem.Status = DownloadItemStatus.Downloading;
                }

                if (queueItem.Title.StartsWith("ENCRYPTED /"))
                {
                    queueItem.Title       = queueItem.Title.Substring(11);
                    queueItem.IsEncrypted = true;
                }

                queueItems.Add(queueItem);
            }

            return(queueItems);
        }
示例#6
0
文件: Pyload.cs 项目: h1srf/Sonarr
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            var status             = GetStatus();
            var baseDownloadFolder = status.OutputRootFolders.FirstOrDefault().FullPath;
            var client             = CreateClient();

            var downloadsRequest = new RestRequest("/api/statusDownloads", Method.GET);
            //client.Execute(downloadsRequest);
            var avcd      = client.Execute(downloadsRequest).Content;
            var downloads = JsonConvert.DeserializeObject <List <PyloadDownloadStatus> >(client.Execute(downloadsRequest).Content);

            var currentDownloads = downloads.Select(p => new DownloadClientItem()
            {
                DownloadId         = p.DownloadId,
                Status             = p.GetDownloadItemStatus(),
                RemainingSize      = (long)p.Bleft,
                TotalSize          = p.Size,
                RemainingTime      = TimeSpan.FromSeconds(p.Eta),
                Message            = p.Statusmsg,
                DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
                Title = Name
            }).ToList();

            var request  = new RestRequest("/api/getQueue", Method.GET);
            var response = client.Execute(request);

            if (response.ResponseStatus != ResponseStatus.Completed)
            {
                throw new DownloadClientException("Error getting queue data", response.ErrorException);
            }

            var queueData = JsonConvert.DeserializeObject <List <PyloadQueue> >(response.Content);

            var currentDownloadIds = currentDownloads.Select(i => i.DownloadId);
            var finished           = queueData.Where(x => !currentDownloadIds.Contains(x.downloadId))
                                     .Select(p => new DownloadClientItem()
            {
                DownloadId         = p.downloadId,
                Status             = p.GetDownloadItemStatus(),
                RemainingSize      = (long)(p.sizetotal - p.sizedone),
                TotalSize          = p.sizetotal ?? 0,
                RemainingTime      = TimeSpan.FromSeconds(10),
                Message            = string.Empty,
                DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
                Title        = Name,
                OutputPath   = new OsPath(System.IO.Path.Combine(baseDownloadFolder, p.folder)),
                CanBeRemoved = true
            }).ToList();

            return(currentDownloads.Union(finished));
        }
示例#7
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            var results = _airDCPPProxy.GetQueueHistory(Settings);

            return(results.Select(result => new DownloadClientItem
            {
                DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
                DownloadId = result.id.ToString(),
                RemainingTime = TimeSpan.FromSeconds((long)result.seconds_left),
                RemainingSize = (long)(result.size - result.downloaded_bytes),
                TotalSize = (long)result.size,
                Title = result.name,
                OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(result.target)),
                Status = result.seconds_left > 0 ? DownloadItemStatus.Downloading : DownloadItemStatus.Completed,
            }));
        }
示例#8
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            foreach (var item in _scanWatchFolder.GetItems(Settings.WatchFolder, ScanGracePeriod))
            {
                yield return(new DownloadClientItem
                {
                    DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
                    DownloadId = Definition.Name + "_" + item.DownloadId,
                    Category = "Readarr",
                    Title = item.Title,

                    TotalSize = item.TotalSize,
                    RemainingTime = item.RemainingTime,

                    OutputPath = item.OutputPath,

                    Status = item.Status,

                    CanMoveFiles = !Settings.ReadOnly,
                    CanBeRemoved = !Settings.ReadOnly
                });
            }
        }
示例#9
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            foreach (var file in _diskProvider.GetFiles(Settings.StrmFolder, SearchOption.TopDirectoryOnly))
            {
                if (Path.GetExtension(file) != ".strm")
                {
                    continue;
                }

                var title = FileNameBuilder.CleanFileName(Path.GetFileName(file));

                var historyItem = new DownloadClientItem
                {
                    DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
                    DownloadId         = GetDownloadClientId(file),
                    Title = title,

                    CanBeRemoved = true,
                    CanMoveFiles = true,

                    TotalSize = _diskProvider.GetFileSize(file),

                    OutputPath = new OsPath(file)
                };

                if (_diskProvider.IsFileLocked(file))
                {
                    historyItem.Status = DownloadItemStatus.Downloading;
                }
                else
                {
                    historyItem.Status = DownloadItemStatus.Completed;
                }

                yield return(historyItem);
            }
        }
示例#10
0
        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.MusicCategory.IsNotNullOrWhiteSpace() && torrent.Category != Settings.MusicCategory)
                {
                    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;
                }

                // No stop ratio data is present, so do not delete
                item.CanMoveFiles = item.CanBeRemoved = false;

                items.Add(item);
            }

            return(items);
        }
示例#11
0
文件: Deluge.cs 项目: rsunde/Readarr
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            IEnumerable <DelugeTorrent> torrents;

            if (Settings.MusicCategory.IsNotNullOrWhiteSpace())
            {
                torrents = _proxy.GetTorrentsByLabel(Settings.MusicCategory, Settings);
            }
            else
            {
                torrents = _proxy.GetTorrents(Settings);
            }

            var items = new List <DownloadClientItem>();

            foreach (var torrent in torrents)
            {
                if (torrent.Hash == null)
                {
                    continue;
                }

                var item = new DownloadClientItem();
                item.DownloadId = torrent.Hash.ToUpper();
                item.Title      = torrent.Name;
                item.Category   = Settings.MusicCategory;

                item.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);

                var outputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.DownloadPath));
                item.OutputPath    = outputPath + torrent.Name;
                item.RemainingSize = torrent.Size - torrent.BytesDownloaded;
                item.SeedRatio     = torrent.Ratio;

                try
                {
                    item.RemainingTime = TimeSpan.FromSeconds(torrent.Eta);
                }
                catch (OverflowException ex)
                {
                    _logger.Debug(ex, "ETA for {0} is too long: {1}", torrent.Name, torrent.Eta);
                    item.RemainingTime = TimeSpan.MaxValue;
                }

                item.TotalSize = torrent.Size;

                if (torrent.State == DelugeTorrentStatus.Error)
                {
                    item.Status  = DownloadItemStatus.Warning;
                    item.Message = "Deluge is reporting an error";
                }
                else if (torrent.IsFinished && torrent.State != DelugeTorrentStatus.Checking)
                {
                    item.Status = DownloadItemStatus.Completed;
                }
                else if (torrent.State == DelugeTorrentStatus.Queued)
                {
                    item.Status = DownloadItemStatus.Queued;
                }
                else if (torrent.State == DelugeTorrentStatus.Paused)
                {
                    item.Status = DownloadItemStatus.Paused;
                }
                else
                {
                    item.Status = DownloadItemStatus.Downloading;
                }

                // Here we detect if Deluge is managing the torrent and whether the seed criteria has been met.
                // This allows drone to delete the torrent as appropriate.
                item.CanMoveFiles = item.CanBeRemoved =
                    torrent.IsAutoManaged &&
                    torrent.StopAtRatio &&
                    torrent.Ratio >= torrent.StopRatio &&
                    torrent.State == DelugeTorrentStatus.Paused;

                items.Add(item);
            }

            return(items);
        }
示例#12
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            var configFunc = new Lazy <TransmissionConfig>(() => _proxy.GetConfig(Settings));
            var torrents   = _proxy.GetTorrents(Settings);

            var items = new List <DownloadClientItem>();

            foreach (var torrent in torrents)
            {
                // If totalsize == 0 the torrent is a magnet downloading metadata
                if (torrent.TotalSize == 0)
                {
                    continue;
                }

                var outputPath = new OsPath(torrent.DownloadDir);

                if (Settings.TvDirectory.IsNotNullOrWhiteSpace())
                {
                    if (!new OsPath(Settings.TvDirectory).Contains(outputPath))
                    {
                        continue;
                    }
                }
                else if (Settings.TvCategory.IsNotNullOrWhiteSpace())
                {
                    var directories = outputPath.FullPath.Split('\\', '/');
                    if (!directories.Contains(Settings.TvCategory))
                    {
                        continue;
                    }
                }

                outputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, outputPath);

                var item = new DownloadClientItem();
                item.DownloadId = torrent.HashString.ToUpper();
                item.Category   = Settings.TvCategory;
                item.Title      = torrent.Name;

                item.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);

                item.OutputPath    = GetOutputPath(outputPath, torrent);
                item.TotalSize     = torrent.TotalSize;
                item.RemainingSize = torrent.LeftUntilDone;
                item.SeedRatio     = torrent.DownloadedEver <= 0 ? 0 :
                                     (double)torrent.UploadedEver / torrent.DownloadedEver;

                if (torrent.Eta >= 0)
                {
                    item.RemainingTime = TimeSpan.FromSeconds(torrent.Eta);
                }

                if (!torrent.ErrorString.IsNullOrWhiteSpace())
                {
                    item.Status  = DownloadItemStatus.Warning;
                    item.Message = torrent.ErrorString;
                }
                else if (torrent.LeftUntilDone == 0 && (torrent.Status == TransmissionTorrentStatus.Stopped ||
                                                        torrent.Status == TransmissionTorrentStatus.Seeding ||
                                                        torrent.Status == TransmissionTorrentStatus.SeedingWait))
                {
                    item.Status = DownloadItemStatus.Completed;
                }
                else if (torrent.IsFinished && torrent.Status != TransmissionTorrentStatus.Check &&
                         torrent.Status != TransmissionTorrentStatus.CheckWait)
                {
                    item.Status = DownloadItemStatus.Completed;
                }
                else if (torrent.Status == TransmissionTorrentStatus.Queued)
                {
                    item.Status = DownloadItemStatus.Queued;
                }
                else
                {
                    item.Status = DownloadItemStatus.Downloading;
                }

                item.CanBeRemoved = HasReachedSeedLimit(torrent, item.SeedRatio, configFunc);
                item.CanMoveFiles = item.CanBeRemoved && torrent.Status == TransmissionTorrentStatus.Stopped;

                items.Add(item);
            }

            return(items);
        }
示例#13
0
        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);
        }
示例#14
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            var nzbTasks     = GetTasks();
            var serialNumber = _serialNumberProvider.GetSerialNumber(Settings);

            var items = new List <DownloadClientItem>();

            long totalRemainingSize = 0;
            long globalSpeed        = nzbTasks.Where(t => t.Status == DownloadStationTaskStatus.Downloading)
                                      .Select(GetDownloadSpeed)
                                      .Sum();

            foreach (var nzb in nzbTasks)
            {
                var outputPath = new OsPath($"/{nzb.Additional.Detail["destination"]}");

                var taskRemainingSize = GetRemainingSize(nzb);

                if (nzb.Status != DownloadStationTaskStatus.Paused)
                {
                    totalRemainingSize += taskRemainingSize;
                }

                if (Settings.TvDirectory.IsNotNullOrWhiteSpace())
                {
                    if (!new OsPath($"/{Settings.TvDirectory}").Contains(outputPath))
                    {
                        continue;
                    }
                }
                else if (Settings.MusicCategory.IsNotNullOrWhiteSpace())
                {
                    var directories = outputPath.FullPath.Split('\\', '/');
                    if (!directories.Contains(Settings.MusicCategory))
                    {
                        continue;
                    }
                }

                var item = new DownloadClientItem()
                {
                    Category           = Settings.MusicCategory,
                    DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
                    DownloadId         = CreateDownloadId(nzb.Id, serialNumber),
                    Title         = nzb.Title,
                    TotalSize     = nzb.Size,
                    RemainingSize = taskRemainingSize,
                    Status        = GetStatus(nzb),
                    Message       = GetMessage(nzb),
                    CanBeRemoved  = true,
                    CanMoveFiles  = true
                };

                if (item.Status != DownloadItemStatus.Paused)
                {
                    item.RemainingTime = GetRemainingTime(totalRemainingSize, globalSpeed);
                }

                if (item.Status == DownloadItemStatus.Completed || item.Status == DownloadItemStatus.Failed)
                {
                    item.OutputPath = GetOutputPath(outputPath, nzb, serialNumber);
                }

                items.Add(item);
            }

            return(items);
        }
示例#15
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            var torrents = _proxy.GetTorrents(Settings);

            foreach (var torrent in torrents)
            {
                var firstFile = torrent.Files?.FirstOrDefault();

                if (firstFile?.Path?.Contains("[METADATA]") == true) //skip metadata download
                {
                    continue;
                }

                var completedLength = long.Parse(torrent.CompletedLength);
                var totalLength     = long.Parse(torrent.TotalLength);
                var uploadedLength  = long.Parse(torrent.UploadLength);
                var downloadSpeed   = long.Parse(torrent.DownloadSpeed);

                var status = DownloadItemStatus.Failed;
                var title  = "";

                if (torrent.Bittorrent?.ContainsKey("info") == true && ((XmlRpcStruct)torrent.Bittorrent["info"]).ContainsKey("name"))
                {
                    title = ((XmlRpcStruct)torrent.Bittorrent["info"])["name"].ToString();
                }

                switch (torrent.Status)
                {
                case "active":
                    if (completedLength == totalLength)
                    {
                        status = DownloadItemStatus.Completed;
                    }
                    else
                    {
                        status = DownloadItemStatus.Downloading;
                    }

                    break;

                case "waiting":
                    status = DownloadItemStatus.Queued;
                    break;

                case "paused":
                    status = DownloadItemStatus.Paused;
                    break;

                case "error":
                    status = DownloadItemStatus.Failed;
                    break;

                case "complete":
                    status = DownloadItemStatus.Completed;
                    break;

                case "removed":
                    status = DownloadItemStatus.Failed;
                    break;
                }

                _logger.Trace($"- aria2 getstatus hash:'{torrent.InfoHash}' gid:'{torrent.Gid}' status:'{status}' total:{totalLength} completed:'{completedLength}'");

                var outputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(GetOutputPath(torrent)));

                yield return(new DownloadClientItem
                {
                    CanMoveFiles = false,
                    CanBeRemoved = torrent.Status == "complete",
                    Category = null,
                    DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
                    DownloadId = torrent.InfoHash?.ToUpper(),
                    IsEncrypted = false,
                    Message = torrent.ErrorMessage,
                    OutputPath = outputPath,
                    RemainingSize = totalLength - completedLength,
                    RemainingTime = downloadSpeed == 0 ? (TimeSpan?)null : new TimeSpan(0, 0, (int)((totalLength - completedLength) / downloadSpeed)),
                    Removed = torrent.Status == "removed",
                    SeedRatio = totalLength > 0 ? (double)uploadedLength / totalLength : 0,
                    Status = status,
                    Title = title,
                    TotalSize = totalLength,
                });
            }
        }
示例#16
0
        private IEnumerable <DownloadClientItem> GetHistory()
        {
            var sabHistory = _proxy.GetHistory(0, _configService.DownloadClientHistoryLimit, Settings.MusicCategory, Settings);

            var historyItems = new List <DownloadClientItem>();

            foreach (var sabHistoryItem in sabHistory.Items)
            {
                if (sabHistoryItem.Status == SabnzbdDownloadStatus.Deleted)
                {
                    continue;
                }

                var historyItem = new DownloadClientItem
                {
                    DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
                    DownloadId         = sabHistoryItem.Id,
                    Category           = sabHistoryItem.Category,
                    Title = sabHistoryItem.Title,

                    TotalSize     = sabHistoryItem.Size,
                    RemainingSize = 0,
                    RemainingTime = TimeSpan.Zero,

                    Message = sabHistoryItem.FailMessage,

                    CanBeRemoved = true,
                    CanMoveFiles = true
                };

                if (sabHistoryItem.Status == SabnzbdDownloadStatus.Failed)
                {
                    if (sabHistoryItem.FailMessage.IsNotNullOrWhiteSpace() &&
                        sabHistoryItem.FailMessage.Equals("Unpacking failed, write error or disk is full?", StringComparison.InvariantCultureIgnoreCase))
                    {
                        historyItem.Status = DownloadItemStatus.Warning;
                    }
                    else
                    {
                        historyItem.Status = DownloadItemStatus.Failed;
                    }
                }
                else if (sabHistoryItem.Status == SabnzbdDownloadStatus.Completed)
                {
                    historyItem.Status = DownloadItemStatus.Completed;
                }
                else
                {
                    // Verifying/Moving etc
                    historyItem.Status = DownloadItemStatus.Downloading;
                }

                var outputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(sabHistoryItem.Storage));

                if (!outputPath.IsEmpty)
                {
                    historyItem.OutputPath = outputPath;

                    var parent = outputPath.Directory;
                    while (!parent.IsEmpty)
                    {
                        if (parent.FileName == sabHistoryItem.Title)
                        {
                            historyItem.OutputPath = parent;
                        }

                        parent = parent.Directory;
                    }
                }

                historyItems.Add(historyItem);
            }

            return(historyItems);
        }
示例#17
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            var torrents = GetTorrents();

            var queueItems = new List <DownloadClientItem>();

            foreach (var torrent in torrents)
            {
                if (torrent.Label != Settings.MusicCategory)
                {
                    continue;
                }

                var item = new DownloadClientItem();
                item.DownloadId         = torrent.Hash;
                item.Title              = torrent.Name;
                item.TotalSize          = torrent.Size;
                item.Category           = torrent.Label;
                item.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);
                item.RemainingSize      = torrent.Remaining;
                item.SeedRatio          = torrent.Ratio;

                if (torrent.Eta != -1)
                {
                    item.RemainingTime = TimeSpan.FromSeconds(torrent.Eta);
                }

                var outputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.RootDownloadPath));

                if (outputPath.FileName == torrent.Name)
                {
                    item.OutputPath = outputPath;
                }
                else
                {
                    item.OutputPath = outputPath + torrent.Name;
                }

                if (torrent.Status.HasFlag(UTorrentTorrentStatus.Error))
                {
                    item.Status  = DownloadItemStatus.Warning;
                    item.Message = "uTorrent is reporting an error";
                }
                else if (torrent.Status.HasFlag(UTorrentTorrentStatus.Loaded) &&
                         torrent.Status.HasFlag(UTorrentTorrentStatus.Checked) && torrent.Remaining == 0 && torrent.Progress == 1.0)
                {
                    item.Status = DownloadItemStatus.Completed;
                }
                else if (torrent.Status.HasFlag(UTorrentTorrentStatus.Paused))
                {
                    item.Status = DownloadItemStatus.Paused;
                }
                else if (torrent.Status.HasFlag(UTorrentTorrentStatus.Started))
                {
                    item.Status = DownloadItemStatus.Downloading;
                }
                else
                {
                    item.Status = DownloadItemStatus.Queued;
                }

                // 'Started' without 'Queued' is when the torrent is 'forced seeding'
                item.CanMoveFiles = item.CanBeRemoved =
                    !torrent.Status.HasFlag(UTorrentTorrentStatus.Queued) &&
                    !torrent.Status.HasFlag(UTorrentTorrentStatus.Started);

                queueItems.Add(item);
            }

            return(queueItems);
        }
示例#18
0
文件: Nzbget.cs 项目: Animarr/Animarr
        private IEnumerable <DownloadClientItem> GetHistory()
        {
            var history = _proxy.GetHistory(Settings).Take(_configService.DownloadClientHistoryLimit).ToList();

            var historyItems = new List <DownloadClientItem>();

            foreach (var item in history)
            {
                var droneParameter = item.Parameters.SingleOrDefault(p => p.Name == "drone");
                var historyItem    = new DownloadClientItem();
                var itemDir        = item.FinalDir.IsNullOrWhiteSpace() ? item.DestDir : item.FinalDir;

                historyItem.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);
                historyItem.DownloadId         = droneParameter == null?item.Id.ToString() : droneParameter.Value.ToString();

                historyItem.Title         = item.Name;
                historyItem.TotalSize     = MakeInt64(item.FileSizeHi, item.FileSizeLo);
                historyItem.OutputPath    = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(itemDir));
                historyItem.Category      = item.Category;
                historyItem.Message       = $"PAR Status: {item.ParStatus} - Unpack Status: {item.UnpackStatus} - Move Status: {item.MoveStatus} - Script Status: {item.ScriptStatus} - Delete Status: {item.DeleteStatus} - Mark Status: {item.MarkStatus}";
                historyItem.Status        = DownloadItemStatus.Completed;
                historyItem.RemainingTime = TimeSpan.Zero;
                historyItem.CanMoveFiles  = true;
                historyItem.CanBeRemoved  = true;

                if (item.DeleteStatus == "MANUAL")
                {
                    continue;
                }

                if (!_successStatus.Contains(item.ParStatus))
                {
                    historyItem.Status = DownloadItemStatus.Failed;
                }

                if (item.UnpackStatus == "SPACE")
                {
                    historyItem.Status = DownloadItemStatus.Warning;
                }
                else if (!_successStatus.Contains(item.UnpackStatus))
                {
                    historyItem.Status = DownloadItemStatus.Failed;
                }

                if (!_successStatus.Contains(item.MoveStatus))
                {
                    historyItem.Status = DownloadItemStatus.Warning;
                }

                if (!_successStatus.Contains(item.ScriptStatus))
                {
                    historyItem.Status = DownloadItemStatus.Failed;
                }

                if (!_successStatus.Contains(item.DeleteStatus) && item.DeleteStatus.IsNotNullOrWhiteSpace())
                {
                    if (_deleteFailedStatus.Contains(item.DeleteStatus))
                    {
                        historyItem.Status = DownloadItemStatus.Failed;
                    }
                    else
                    {
                        historyItem.Status = DownloadItemStatus.Warning;
                    }
                }

                historyItems.Add(historyItem);
            }

            return(historyItems);
        }
示例#19
0
        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);
        }
示例#20
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            var torrents = _proxy.GetTorrents(Settings);

            var items = new List <DownloadClientItem>();

            foreach (var torrent in torrents)
            {
                if (Settings.Category.IsNotNullOrWhiteSpace() && torrent.Label != Settings.Category)
                {
                    continue;
                }

                var outputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.SavePath));
                var eta        = TimeSpan.FromSeconds(0);

                if (torrent.DownloadRate > 0 && torrent.TotalSize > 0)
                {
                    eta = TimeSpan.FromSeconds(torrent.TotalSize / (double)torrent.DownloadRate);
                }

                var item = new DownloadClientItem
                {
                    DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
                    DownloadId         = torrent.InfoHash.ToUpper(),
                    OutputPath         = outputPath + torrent.Name,
                    RemainingSize      = torrent.TotalSize - torrent.DownloadedBytes,
                    RemainingTime      = eta,
                    Title     = torrent.Name,
                    TotalSize = torrent.TotalSize,
                    SeedRatio = torrent.DownloadedBytes <= 0 ? 0 :
                                (double)torrent.UploadedBytes / torrent.DownloadedBytes
                };

                if (!string.IsNullOrEmpty(torrent.Error))
                {
                    item.Status  = DownloadItemStatus.Warning;
                    item.Message = torrent.Error;
                }
                else if (torrent.IsFinished && torrent.State != HadoukenTorrentState.CheckingFiles)
                {
                    item.Status = DownloadItemStatus.Completed;
                }
                else if (torrent.State == HadoukenTorrentState.QueuedForChecking)
                {
                    item.Status = DownloadItemStatus.Queued;
                }
                else if (torrent.State == HadoukenTorrentState.Paused)
                {
                    item.Status = DownloadItemStatus.Paused;
                }
                else
                {
                    item.Status = DownloadItemStatus.Downloading;
                }

                item.CanMoveFiles = item.CanBeRemoved = (torrent.IsFinished && torrent.State == HadoukenTorrentState.Paused);

                items.Add(item);
            }

            return(items);
        }
示例#21
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            var version  = Proxy.GetApiVersion(Settings);
            var config   = Proxy.GetConfig(Settings);
            var torrents = Proxy.GetTorrents(Settings);

            var queueItems = new List <DownloadClientItem>();

            foreach (var torrent in torrents)
            {
                var item = new DownloadClientItem()
                {
                    DownloadId         = torrent.Hash.ToUpper(),
                    Category           = torrent.Category.IsNotNullOrWhiteSpace() ? torrent.Category : torrent.Label,
                    Title              = torrent.Name,
                    TotalSize          = torrent.Size,
                    DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
                    RemainingSize      = (long)(torrent.Size * (1.0 - torrent.Progress)),
                    RemainingTime      = GetRemainingTime(torrent),
                    SeedRatio          = torrent.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).
                item.CanMoveFiles = item.CanBeRemoved = torrent.State == "pausedUP" && HasReachedSeedLimit(torrent, config);

                switch (torrent.State)
                {
                case "error":     // some error occurred, applies to paused torrents
                    item.Status  = DownloadItemStatus.Failed;
                    item.Message = "qBittorrent is reporting an error";
                    break;

                case "pausedDL":     // torrent is paused and has NOT finished downloading
                    item.Status = DownloadItemStatus.Paused;
                    break;

                case "queuedDL":     // queuing is enabled and torrent is queued for download
                case "checkingDL":   // same as checkingUP, but torrent has NOT finished downloading
                case "checkingUP":   // torrent has finished downloading and is being checked. Set when `recheck torrent on completion` is enabled. In the event the check fails we shouldn't treat it as completed.
                    item.Status = DownloadItemStatus.Queued;
                    break;

                case "pausedUP":                        // torrent is paused and has finished downloading:
                case "uploading":                       // torrent is being seeded and data is being transferred
                case "stalledUP":                       // torrent is being seeded, but no connection were made
                case "queuedUP":                        // queuing is enabled and torrent is queued for upload
                case "forcedUP":                        // torrent has finished downloading and is being forcibly seeded
                    item.Status        = DownloadItemStatus.Completed;
                    item.RemainingTime = TimeSpan.Zero; // qBittorrent sends eta=8640000 for completed torrents
                    break;

                case "stalledDL":     // torrent is being downloaded, but no connection were made
                    item.Status  = DownloadItemStatus.Warning;
                    item.Message = "The download is stalled with no connections";
                    break;

                case "missingFiles":     // torrent is being downloaded, but no connection were made
                    item.Status  = DownloadItemStatus.Warning;
                    item.Message = "The download is missing files";
                    break;

                case "metaDL":     // torrent magnet is being downloaded
                    if (config.DhtEnabled)
                    {
                        item.Status = DownloadItemStatus.Queued;
                    }
                    else
                    {
                        item.Status  = DownloadItemStatus.Warning;
                        item.Message = "qBittorrent cannot resolve magnet link with DHT disabled";
                    }

                    break;

                case "forcedDL":    //torrent is being downloaded, and was forced started
                case "moving":      // torrent is being moved from a folder
                case "downloading": // torrent is being downloaded and data is being transferred
                    item.Status = DownloadItemStatus.Downloading;
                    break;

                default:     // new status in API? default to downloading
                    item.Message = "Unknown download state: " + torrent.State;
                    _logger.Info(item.Message);
                    item.Status = DownloadItemStatus.Downloading;
                    break;
                }

                if (version >= new Version("2.6.1"))
                {
                    if (torrent.ContentPath != torrent.SavePath)
                    {
                        item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.ContentPath));
                    }
                    else if (item.Status == DownloadItemStatus.Completed)
                    {
                        item.Status  = DownloadItemStatus.Warning;
                        item.Message = "Unable to import since content path is equal to root download directory, perhaps Keep top-level folder was disabled for this torrent?";
                    }
                }

                queueItems.Add(item);
            }

            return(queueItems);
        }
示例#22
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            List <NzbVortexQueueItem> vortexQueue;

            try
            {
                vortexQueue = _proxy.GetQueue(30, Settings);
            }
            catch (DownloadClientException ex)
            {
                _logger.Warn("Couldn't get download queue. {0}", ex.Message);
                return(Enumerable.Empty <DownloadClientItem>());
            }

            var queueItems = new List <DownloadClientItem>();

            foreach (var vortexQueueItem in vortexQueue)
            {
                var queueItem = new DownloadClientItem();

                queueItem.DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this);
                queueItem.DownloadId         = vortexQueueItem.AddUUID ?? vortexQueueItem.Id.ToString();
                queueItem.Category           = vortexQueueItem.GroupName;
                queueItem.Title         = vortexQueueItem.UiTitle;
                queueItem.TotalSize     = vortexQueueItem.TotalDownloadSize;
                queueItem.RemainingSize = vortexQueueItem.TotalDownloadSize - vortexQueueItem.DownloadedSize;
                queueItem.RemainingTime = null;
                queueItem.CanBeRemoved  = true;
                queueItem.CanMoveFiles  = true;

                if (vortexQueueItem.IsPaused)
                {
                    queueItem.Status = DownloadItemStatus.Paused;
                }
                else
                {
                    switch (vortexQueueItem.State)
                    {
                    case NzbVortexStateType.Waiting:
                        queueItem.Status = DownloadItemStatus.Queued;
                        break;

                    case NzbVortexStateType.Done:
                        queueItem.Status = DownloadItemStatus.Completed;
                        break;

                    case NzbVortexStateType.UncompressFailed:
                    case NzbVortexStateType.CheckFailedDataCorrupt:
                    case NzbVortexStateType.BadlyEncoded:
                        queueItem.Status = DownloadItemStatus.Failed;
                        break;

                    default:
                        queueItem.Status = DownloadItemStatus.Downloading;
                        break;
                    }
                }

                queueItem.OutputPath = GetOutputPath(vortexQueueItem, queueItem);

                if (vortexQueueItem.State == NzbVortexStateType.PasswordRequest)
                {
                    queueItem.IsEncrypted = true;
                }

                if (queueItem.Status == DownloadItemStatus.Completed)
                {
                    queueItem.RemainingTime = TimeSpan.Zero;
                }

                queueItems.Add(queueItem);
            }

            return(queueItems);
        }