コード例 #1
0
        public async Task Initialize()
        {
            // When starting up reset any pending downloads or unpackings so that they are restarted.
            var torrents = await _torrents.Get();

            torrents = torrents.Where(m => m.Completed == null).ToList();

            var downloads = torrents.SelectMany(m => m.Downloads)
                            .Where(m => m.DownloadQueued != null && m.DownloadStarted != null && m.DownloadFinished == null)
                            .OrderBy(m => m.DownloadQueued);

            foreach (var download in downloads)
            {
                await _downloads.UpdateDownloadStarted(download.DownloadId, null);
            }

            var unpacks = torrents.SelectMany(m => m.Downloads)
                          .Where(m => m.UnpackingQueued != null && m.UnpackingStarted != null && m.UnpackingFinished == null)
                          .OrderBy(m => m.DownloadQueued);

            foreach (var download in unpacks)
            {
                await _downloads.UpdateUnpackingStarted(download.DownloadId, null);
            }
        }
コード例 #2
0
        public async Task <ActionResult <IList <Torrent> > > Get()
        {
            var results = await _torrents.Get();

            // Prevent infinite recursion when serializing
            foreach (var file in results.SelectMany(torrent => torrent.Downloads))
            {
                file.Torrent = null;
            }

            return(Ok(results));
        }
コード例 #3
0
        private async Task ProcessAutoDownloads(IDownloads downloads, ISettings settings, ITorrents torrents)
        {
            var allTorrents = await torrents.Get();

            allTorrents = allTorrents.Where(m => (m.Status == TorrentStatus.WaitingForDownload && m.AutoDownload && m.Downloads.Count == 0) || m.Status == TorrentStatus.DownloadQueued)
                          .ToList();

            foreach (var torrent in allTorrents)
            {
                await torrents.Download(torrent.TorrentId);
            }
        }
コード例 #4
0
        public async Task Update()
        {
            var torrents = await _torrents.Get();

            // Prevent infinite recursion when serializing
            foreach (var file in torrents.SelectMany(torrent => torrent.Downloads))
            {
                file.Torrent = null;
            }

            await _hub.Clients.All.SendCoreAsync("update",
                                                 new Object[]
            {
                torrents
            });
        }
コード例 #5
0
        public async Task <IList <TorrentInfo> > TorrentInfo()
        {
            var savePath = await AppDefaultSavePath();

            var results = new List <TorrentInfo>();

            var torrents = await _torrents.Get();

            var prio = 0;

            foreach (var torrent in torrents)
            {
                var result = new TorrentInfo();
                result.AddedOn           = torrent.RdAdded.ToUnixTimeSeconds();
                result.AmountLeft        = (Int64)(torrent.RdSize * (100.0 - torrent.RdProgress) / 100.0);
                result.AutoTmm           = false;
                result.Availability      = 2;
                result.Category          = torrent.Category ?? "";
                result.Completed         = (Int64)(torrent.RdSize * (torrent.RdProgress / 100.0));
                result.CompletionOn      = torrent.RdEnded?.ToUnixTimeSeconds();
                result.DlLimit           = -1;
                result.Dlspeed           = torrent.RdSpeed ?? 0;
                result.Downloaded        = (Int64)(torrent.RdSize * (torrent.RdProgress / 100.0));
                result.DownloadedSession = (Int64)(torrent.RdSize * (torrent.RdProgress / 100.0));
                result.Eta              = 0;
                result.FlPiecePrio      = false;
                result.ForceStart       = false;
                result.Hash             = torrent.Hash;
                result.LastActivity     = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                result.MagnetUri        = "";
                result.MaxRatio         = -1;
                result.MaxSeedingTime   = -1;
                result.Name             = torrent.RdName;
                result.NumComplete      = 10;
                result.NumIncomplete    = 0;
                result.NumLeechs        = 100;
                result.NumSeeds         = 100;
                result.Priority         = ++prio;
                result.Progress         = (Int64)(torrent.RdProgress / 100.0);
                result.Ratio            = 1;
                result.RatioLimit       = 1;
                result.SavePath         = savePath;
                result.SeedingTimeLimit = 1;
                result.SeenComplete     = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                result.SeqDl            = false;
                result.Size             = torrent.RdSize;
                result.SuperSeeding     = false;
                result.Tags             = "";
                result.TimeActive       = (Int64)(torrent.RdAdded - DateTimeOffset.UtcNow).TotalMinutes;
                result.TotalSize        = torrent.RdSize;
                result.Tracker          = "udp://tracker.opentrackr.org:1337";
                result.UpLimit          = -1;
                result.Uploaded         = (Int64)(torrent.RdSize * (torrent.RdProgress / 100.0));
                result.UploadedSession  = (Int64)(torrent.RdSize * (torrent.RdProgress / 100.0));
                result.Upspeed          = torrent.RdSpeed ?? 0;
                result.State            = torrent.Status switch
                {
                    TorrentStatus.RealDebrid => "downloading",
                    TorrentStatus.WaitingForDownload => "downloading",
                    TorrentStatus.DownloadQueued => "downloading",
                    TorrentStatus.Downloading => "downloading",
                    TorrentStatus.Finished => "pausedUP",
                    TorrentStatus.Error => "error",
                    _ => throw new ArgumentOutOfRangeException()
                };

                results.Add(result);
            }

            return(results);
        }
コード例 #6
0
        public async Task <IList <TorrentInfo> > TorrentInfo()
        {
            var savePath = await AppDefaultSavePath();

            var results = new List <TorrentInfo>();

            var torrents = await _torrents.Get();

            var prio = 0;

            foreach (var torrent in torrents)
            {
                var downloadPath = savePath;

                if (!String.IsNullOrWhiteSpace(torrent.Category))
                {
                    downloadPath = Path.Combine(downloadPath, torrent.Category);
                }

                var torrentPath = Path.Combine(downloadPath, torrent.RdName);

                var bytesDone  = torrent.RdProgress;
                var bytesTotal = torrent.RdSize;
                var speed      = torrent.RdSpeed ?? 0;

                if (torrent.Downloads.Count > 0)
                {
                    bytesDone  = torrent.Downloads.Sum(m => m.BytesDone);
                    bytesTotal = torrent.Downloads.Sum(m => m.BytesTotal);
                    speed      = (Int32)torrent.Downloads.Average(m => m.Speed);
                }

                var result = new TorrentInfo
                {
                    AddedOn           = torrent.Added.ToUnixTimeSeconds(),
                    AmountLeft        = bytesTotal - bytesDone,
                    AutoTmm           = false,
                    Availability      = 2,
                    Category          = torrent.Category ?? "",
                    Completed         = bytesDone,
                    CompletionOn      = torrent.Completed?.ToUnixTimeSeconds(),
                    ContentPath       = torrentPath,
                    DlLimit           = -1,
                    Dlspeed           = speed,
                    Downloaded        = bytesDone,
                    DownloadedSession = bytesDone,
                    Eta              = 0,
                    FlPiecePrio      = false,
                    ForceStart       = false,
                    Hash             = torrent.Hash,
                    LastActivity     = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
                    MagnetUri        = "",
                    MaxRatio         = -1,
                    MaxSeedingTime   = -1,
                    Name             = torrent.RdName,
                    NumComplete      = 10,
                    NumIncomplete    = 0,
                    NumLeechs        = 100,
                    NumSeeds         = 100,
                    Priority         = ++prio,
                    Progress         = bytesDone / (Single)bytesTotal,
                    Ratio            = 1,
                    RatioLimit       = 1,
                    SavePath         = downloadPath,
                    SeedingTimeLimit = 1,
                    SeenComplete     = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
                    SeqDl            = false,
                    Size             = bytesTotal,
                    State            = "downloading",
                    SuperSeeding     = false,
                    Tags             = "",
                    TimeActive       = (Int64)(DateTimeOffset.UtcNow - torrent.Added).TotalSeconds,
                    TotalSize        = bytesTotal,
                    Tracker          = "udp://tracker.opentrackr.org:1337",
                    UpLimit          = -1,
                    Uploaded         = bytesDone,
                    UploadedSession  = bytesDone,
                    Upspeed          = speed
                };

                if (torrent.Completed.HasValue)
                {
                    // Indicates completed torrent and not seeding anymore.
                    result.State = "pausedUP";

                    if (torrent.Downloads.Count > 0)
                    {
                        var error = torrent.Downloads.FirstOrDefault(m => m.Error != null);

                        if (error != null)
                        {
                            result.State = "error";
                        }
                    }
                }

                results.Add(result);
            }

            return(results);
        }
コード例 #7
0
        public async Task <ActionResult <IList <Torrent> > > Get()
        {
            var result = await _torrents.Get();

            return(Ok(result));
        }