Ejemplo n.º 1
0
        private async Task Update(Torrent torrent, RDNET.Torrent rdTorrent)
        {
            if (!String.IsNullOrWhiteSpace(rdTorrent.Filename))
            {
                torrent.RdName = rdTorrent.Filename;
            }
            else if (!String.IsNullOrWhiteSpace(rdTorrent.OriginalFilename))
            {
                torrent.RdName = rdTorrent.OriginalFilename;
            }

            if (rdTorrent.Bytes > 0)
            {
                torrent.RdSize = rdTorrent.Bytes;
            }
            else if (rdTorrent.OriginalBytes > 0)
            {
                torrent.RdSize = rdTorrent.OriginalBytes;
            }

            if (rdTorrent.Files != null)
            {
                torrent.RdFiles = JsonConvert.SerializeObject(rdTorrent.Files);
            }

            torrent.RdHost      = rdTorrent.Host;
            torrent.RdSplit     = rdTorrent.Split;
            torrent.RdProgress  = rdTorrent.Progress;
            torrent.RdAdded     = rdTorrent.Added;
            torrent.RdEnded     = rdTorrent.Ended;
            torrent.RdSpeed     = rdTorrent.Speed;
            torrent.RdSeeders   = rdTorrent.Seeders;
            torrent.RdStatusRaw = rdTorrent.Status;

            torrent.RdStatus = rdTorrent.Status switch
            {
                "magnet_error" => RealDebridStatus.Error,
                "magnet_conversion" => RealDebridStatus.Processing,
                "waiting_files_selection" => RealDebridStatus.WaitingForFileSelection,
                "queued" => RealDebridStatus.Downloading,
                "downloading" => RealDebridStatus.Downloading,
                "downloaded" => RealDebridStatus.Finished,
                "error" => RealDebridStatus.Error,
                "virus" => RealDebridStatus.Error,
                "compressing" => RealDebridStatus.Downloading,
                "uploading" => RealDebridStatus.Finished,
                "dead" => RealDebridStatus.Error,
                _ => RealDebridStatus.Error
            };

            await _torrentData.UpdateRdData(torrent);
        }
    }
Ejemplo n.º 2
0
        private async Task Update(Torrent torrent, RDNET.Torrent rdTorrent)
        {
            if (!String.IsNullOrWhiteSpace(rdTorrent.Filename))
            {
                torrent.RdName = rdTorrent.Filename;
            }
            else if (!String.IsNullOrWhiteSpace(rdTorrent.OriginalFilename))
            {
                torrent.RdName = rdTorrent.OriginalFilename;
            }

            if (rdTorrent.Bytes > 0)
            {
                torrent.RdSize = rdTorrent.Bytes;
            }
            else if (rdTorrent.OriginalBytes > 0)
            {
                torrent.RdSize = rdTorrent.OriginalBytes;
            }

            if (rdTorrent.Files != null)
            {
                torrent.RdFiles = JsonConvert.SerializeObject(rdTorrent.Files);
            }

            torrent.RdHost     = rdTorrent.Host;
            torrent.RdSplit    = rdTorrent.Split;
            torrent.RdProgress = rdTorrent.Progress;
            torrent.RdStatus   = rdTorrent.Status;
            torrent.RdAdded    = rdTorrent.Added;
            torrent.RdEnded    = rdTorrent.Ended;
            torrent.RdSpeed    = rdTorrent.Speed;
            torrent.RdSeeders  = rdTorrent.Seeders;

            await _torrentData.UpdateRdData(torrent);

            if (torrent.Status == TorrentStatus.RealDebrid)
            {
                if (torrent.Status == TorrentStatus.RealDebrid && torrent.RdProgress == 100)
                {
                    await _torrentData.UpdateStatus(torrent.TorrentId, TorrentStatus.WaitingForDownload);
                }
                else
                {
                    // Current status of the torrent: magnet_error, magnet_conversion, waiting_files_selection, queued, downloading, downloaded, error, virus, compressing, uploading, dead
                    torrent.Status = rdTorrent.Status switch
                    {
                        "magnet_error" => TorrentStatus.Error,
                        "error" => TorrentStatus.Error,
                        "virus" => TorrentStatus.Error,
                        "dead" => TorrentStatus.Error,
                        _ => TorrentStatus.RealDebrid
                    };

                    await _torrentData.UpdateStatus(torrent.TorrentId, torrent.Status);
                }
            }

            if (rdTorrent.Files != null && rdTorrent.Files.Count > 0)
            {
                if (!rdTorrent.Files.Any(m => m.Selected))
                {
                    var fileIds = rdTorrent.Files
                                  .Select(m => m.Id.ToString())
                                  .ToArray();

                    await RdNetClient.SelectTorrentFilesAsync(rdTorrent.Id, fileIds);
                }
            }
        }
    }