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);
        }
        protected override string AddFromMagnetLink(ReleaseInfo release, string hash, string magnetLink)
        {
            var hashedSerialNumber = _serialNumberProvider.GetSerialNumber(Settings);

            _dsTaskProxy.AddTaskFromUrl(magnetLink, GetDownloadDirectory(), Settings);

            var item = GetTasks().SingleOrDefault(t => t.Additional.Detail["uri"] == magnetLink);

            if (item != null)
            {
                _logger.Debug("{0} added correctly", release);
                return(CreateDownloadId(item.Id, hashedSerialNumber));
            }

            _logger.Debug("No such task {0} in Download Station", magnetLink);

            throw new DownloadClientException("Failed to add magnet task to Download Station");
        }
示例#3
0
        protected override string AddFromNzbFile(ReleaseInfo release, string filename, byte[] fileContent)
        {
            var hashedSerialNumber = _serialNumberProvider.GetSerialNumber(Settings);

            _dsTaskProxy.AddTaskFromData(fileContent, filename, GetDownloadDirectory(), Settings);

            var items = GetTasks().Where(t => t.Additional.Detail["uri"] == filename);

            var item = items.SingleOrDefault();

            if (item != null)
            {
                _logger.Debug("{0} added correctly", release);
                return(CreateDownloadId(item.Id, hashedSerialNumber));
            }

            _logger.Debug("No such task {0} in Download Station", filename);

            throw new DownloadClientException("Failed to add NZB task to Download Station");
        }
示例#4
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.TvCategory.IsNotNullOrWhiteSpace())
                {
                    var directories = outputPath.FullPath.Split('\\', '/');
                    if (!directories.Contains(Settings.TvCategory))
                    {
                        continue;
                    }
                }

                var item = new DownloadClientItem()
                {
                    Category       = Settings.TvCategory,
                    DownloadClient = Definition.Name,
                    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);
        }