Exemple #1
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            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,
                    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.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)
                {
                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 "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;
                }

                queueItems.Add(item);
            }

            return(queueItems);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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;
                }

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

                items.Add(item);
            }

            return(items);
        }
Exemple #5
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);
        }
Exemple #6
0
        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")
                {
                    if (item.MarkStatus == "BAD")
                    {
                        historyItem.Status = DownloadItemStatus.Failed;

                        historyItems.Add(historyItem);
                    }

                    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);
        }
Exemple #7
0
        public void Setup()
        {
            _rejectedDecisions = new List <ImportDecision <LocalBook> >();
            _approvedDecisions = new List <ImportDecision <LocalBook> >();

            var author = Builder <Author> .CreateNew()
                         .With(e => e.QualityProfile = new QualityProfile {
                Items = Qualities.QualityFixture.GetDefaultQualities()
            })
                         .With(s => s.Path = @"C:\Test\Music\Alien Ant Farm".AsOsAgnostic())
                         .Build();

            var book = Builder <Book> .CreateNew()
                       .With(e => e.Author = author)
                       .Build();

            var edition = Builder <Edition> .CreateNew()
                          .With(e => e.Book      = book)
                          .With(e => e.Monitored = true)
                          .Build();

            book.Editions = new List <Edition> {
                edition
            };

            var rootFolder = Builder <RootFolder> .CreateNew()
                             .With(r => r.IsCalibreLibrary = false)
                             .Build();

            _rejectedDecisions.Add(new ImportDecision <LocalBook>(new LocalBook(), new Rejection("Rejected!")));
            _rejectedDecisions.Add(new ImportDecision <LocalBook>(new LocalBook(), new Rejection("Rejected!")));
            _rejectedDecisions.Add(new ImportDecision <LocalBook>(new LocalBook(), new Rejection("Rejected!")));

            _approvedDecisions.Add(new ImportDecision <LocalBook>(
                                       new LocalBook
            {
                Author        = author,
                Book          = book,
                Edition       = edition,
                Part          = 1,
                Path          = Path.Combine(author.Path, "Alien Ant Farm - 01 - Pilot.mp3"),
                Quality       = new QualityModel(Quality.MP3),
                FileTrackInfo = new ParsedTrackInfo
                {
                    ReleaseGroup = "DRONE"
                }
            }));

            Mocker.GetMock <IUpgradeMediaFiles>()
            .Setup(s => s.UpgradeBookFile(It.IsAny <BookFile>(), It.IsAny <LocalBook>(), It.IsAny <bool>()))
            .Returns(new BookFileMoveResult());

            _clientInfo = Builder <DownloadClientItemClientInfo> .CreateNew().Build();

            _downloadClientItem = Builder <DownloadClientItem> .CreateNew().With(x => x.DownloadClientInfo = _clientInfo).Build();

            Mocker.GetMock <IMediaFileService>()
            .Setup(s => s.GetFilesByBook(It.IsAny <int>()))
            .Returns(new List <BookFile>());

            Mocker.GetMock <IRootFolderService>()
            .Setup(s => s.GetBestRootFolder(It.IsAny <string>()))
            .Returns(rootFolder);

            Mocker.GetMock <IEditionService>()
            .Setup(s => s.SetMonitored(edition))
            .Returns(new List <Edition> {
                edition
            });
        }
Exemple #8
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)
                {
                    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,
                });
            }
        }
Exemple #9
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.MusicCategory.IsNotNullOrWhiteSpace())
                {
                    var directories = outputPath.FullPath.Split('\\', '/');
                    if (!directories.Contains(Settings.MusicCategory))
                    {
                        continue;
                    }
                }

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

                var item = new DownloadClientItem();
                item.DownloadId = torrent.HashString.ToUpper();
                item.Category   = Settings.MusicCategory;
                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);
        }
Exemple #10
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);
        }
Exemple #11
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);
        }
Exemple #12
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);
        }
Exemple #13
0
        public override IEnumerable <DownloadClientItem> GetItems()
        {
            IEnumerable <DelugeTorrent> torrents;

            if (Settings.MovieCategory.IsNotNullOrWhiteSpace())
            {
                torrents = _proxy.GetTorrentsByLabel(Settings.MovieCategory, 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.MovieCategory;

                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);
        }
        public void Setup()
        {
            _rejectedDecisions = new List <ImportDecision <LocalTrack> >();
            _approvedDecisions = new List <ImportDecision <LocalTrack> >();

            var artist = Builder <Artist> .CreateNew()
                         .With(e => e.QualityProfile = new QualityProfile {
                Items = Qualities.QualityFixture.GetDefaultQualities()
            })
                         .With(s => s.Path = @"C:\Test\Music\Alien Ant Farm".AsOsAgnostic())
                         .Build();

            var album = Builder <Album> .CreateNew()
                        .With(e => e.Artist = artist)
                        .Build();

            var release = Builder <AlbumRelease> .CreateNew()
                          .With(e => e.AlbumId   = album.Id)
                          .With(e => e.Monitored = true)
                          .Build();

            album.AlbumReleases = new List <AlbumRelease> {
                release
            };

            var tracks = Builder <Track> .CreateListOfSize(5)
                         .Build();

            _rejectedDecisions.Add(new ImportDecision <LocalTrack>(new LocalTrack(), new Rejection("Rejected!")));
            _rejectedDecisions.Add(new ImportDecision <LocalTrack>(new LocalTrack(), new Rejection("Rejected!")));
            _rejectedDecisions.Add(new ImportDecision <LocalTrack>(new LocalTrack(), new Rejection("Rejected!")));

            foreach (var track in tracks)
            {
                _approvedDecisions.Add(new ImportDecision <LocalTrack>(
                                           new LocalTrack
                {
                    Artist  = artist,
                    Album   = album,
                    Release = release,
                    Tracks  = new List <Track> {
                        track
                    },
                    Path          = Path.Combine(artist.Path, "Alien Ant Farm - 01 - Pilot.mp3"),
                    Quality       = new QualityModel(Quality.MP3_256),
                    FileTrackInfo = new ParsedTrackInfo
                    {
                        ReleaseGroup = "DRONE"
                    }
                }));
            }

            Mocker.GetMock <IUpgradeMediaFiles>()
            .Setup(s => s.UpgradeTrackFile(It.IsAny <TrackFile>(), It.IsAny <LocalTrack>(), It.IsAny <bool>()))
            .Returns(new TrackFileMoveResult());

            _clientInfo = Builder <DownloadClientItemClientInfo> .CreateNew().Build();

            _downloadClientItem = Builder <DownloadClientItem> .CreateNew().With(x => x.DownloadClientInfo = _clientInfo).Build();

            Mocker.GetMock <IMediaFileService>()
            .Setup(s => s.GetFilesByAlbum(It.IsAny <int>()))
            .Returns(new List <TrackFile>());
        }