Exemplo n.º 1
0
        private void HandleUnprocessedTorrent(Torrent torrent)
        {
            if (torrent.IsDownloaded && !_torrentManager.HasTorrentBeenProcessed(torrent))
            {
                if (processedTorrentsCount >= _config.MaxProcessTorrentsInBatch)
                {
                    // Enough in this batch already. Exit.
                    _logger.Debug($"- Already Processed {processedTorrentsCount} in this batch which was the configured max, exiting..");
                    return;
                }

                // Otherwise, lets unpack/process!
                processedTorrentsCount++;

                // Mark as in progress
                _torrentManager.MarkTorrentAsProcessing(torrent);

                var unpackedOk = unpacker.CopyAndUnpack(torrent);
                if (unpackedOk)
                {
                    // Mark torrent as finished
                    _torrentManager.MarkTorrentAsProcessed(torrent);
                    _logger.Info($"- Torrent process OK!");

                    if (_torrentManager.HasTorrentBeenProcessed(torrent) && _torrentManager.HasTorrentGoalsBeenReached(torrent))
                    {
                        // Delete if goals reached and torrent processed ok, if configured as such.
                        if (_config.DeleteFromTorrentsFolderWhenUnpacked)
                        {
                            _logger.Info("- Deleting (torrent is processed and goals has been reached.");
                            _torrentManager.DeleteTorrent(torrent);
                        }
                    }
                }
                else
                {
                    // Unpack error!! Quit!
                    _logger.Error($"- Failed to process torrent! Investigate logs. {nameof(unpacker.LastUnpackCommand)}: {unpacker.LastUnpackCommand}");
                    _torrentManager.MarkTorrentAsProcessFailed(torrent);
                }
            }
        }