예제 #1
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            QBittorrentPreferences    config;
            List <QBittorrentTorrent> torrents;

            try
            {
                config   = _proxy.GetConfig(Settings);
                torrents = _proxy.GetTorrents(Settings);
            }
            catch (DownloadClientException ex)
            {
                _logger.Error(ex, ex.Message);
                return(Enumerable.Empty <DownloadClientItem>());
            }

            var queueItems = new List <DownloadClientItem>();

            foreach (var torrent in torrents)
            {
                var item = new DownloadClientItem();
                item.DownloadId     = torrent.Hash.ToUpper();
                item.Category       = torrent.Category.IsNotNullOrWhiteSpace() ? torrent.Category : torrent.Label;
                item.Title          = torrent.Name;
                item.TotalSize      = torrent.Size;
                item.DownloadClient = Definition.Name;
                item.RemainingSize  = (long)(torrent.Size * (1.0 - torrent.Progress));
                item.RemainingTime  = TimeSpan.FromSeconds(torrent.Eta);

                item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.SavePath));

                // 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.IsReadOnly = (config.MaxRatioEnabled && config.MaxRatio > torrent.Ratio) || torrent.State != "pausedUP";

                if (!item.OutputPath.IsEmpty && item.OutputPath.FileName != torrent.Name)
                {
                    item.OutputPath += torrent.Name;
                }

                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
                    item.Status = DownloadItemStatus.Queued;
                    break;

                case "pausedUP":                        // torrent is paused and has finished downloading
                case "uploading":                       // torrent is being seeded and data is being transfered
                case "stalledUP":                       // torrent is being seeded, but no connection were made
                case "queuedUP":                        // queuing is enabled and torrent is queued for upload
                case "checkingUP":                      // torrent has finished downloading and is being checked
                    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 "downloading": // torrent is being downloaded and data is being transfered
                default:            // new status in API? default to downloading
                    item.Status = DownloadItemStatus.Downloading;
                    break;
                }

                queueItems.Add(item);
            }

            return(queueItems);
        }
예제 #2
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            List <QBittorrentTorrent> torrents;

            try
            {
                torrents = _proxy.GetTorrents(Settings);
            }
            catch (DownloadClientException ex)
            {
                _logger.ErrorException(ex.Message, ex);
                return(Enumerable.Empty <DownloadClientItem>());
            }

            var queueItems = new List <DownloadClientItem>();

            foreach (var torrent in torrents)
            {
                var item = new DownloadClientItem();
                item.DownloadId     = torrent.Hash.ToUpper();
                item.Category       = torrent.Label;
                item.Title          = torrent.Name;
                item.TotalSize      = torrent.Size;
                item.DownloadClient = Definition.Name;
                item.RemainingSize  = (long)(torrent.Size * (1.0 - torrent.Progress));
                item.RemainingTime  = TimeSpan.FromSeconds(torrent.Eta);

                item.OutputPath = _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(torrent.SavePath));

                // At the moment there isn't an easy way to detect if the torrent has
                // reached the seeding limit, We would need to check the preferences
                // and still not be completely sure if that torrent has a limit set for it
                item.IsReadOnly = true;

                if (!item.OutputPath.IsEmpty && item.OutputPath.FileName != torrent.Name)
                {
                    item.OutputPath += torrent.Name;
                }

                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
                    item.Status = DownloadItemStatus.Queued;
                    break;

                case "pausedUP":                        // torrent is paused and has finished downloading
                case "uploading":                       // torrent is being seeded and data is being transfered
                case "stalledUP":                       // torrent is being seeded, but no connection were made
                case "queuedUP":                        // queuing is enabled and torrent is queued for upload
                case "checkingUP":                      // torrent has finished downloading and is being checked
                    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 "downloading": // torrent is being downloaded and data is being transfered
                default:            // new status in API? default to downloading
                    item.Status = DownloadItemStatus.Downloading;
                    break;
                }

                queueItems.Add(item);
            }

            return(queueItems);
        }