Exemplo n.º 1
0
        async Task SummarizeTorrent(FileInfo torrent)
        {
            var content = await File.ReadAllBytesAsync(torrent.FullName);

            if (!BEnc.TryParseExpr(content, out var expr, out int read) ||
                read != content.Length ||
                expr == null)
            {
                Console.WriteLine($"Something went wrong reading {torrent.FullName} at offset {read}");
                return;
            }

            var fileInfo = MetaInfoSerializer.Deserialize <TorrentFileDto>(expr);

            byte[] infoHash = expr["info"] !.Hash();

            Console.WriteLine($"Summary for '{fileInfo.Info.Name}'");
            Console.WriteLine($"InfoHash: {Convert.ToHexString(infoHash)}");
            var files = fileInfo.Info.Files;

            if (files != null)
            {
                var maxNameLen = files.Select(f => string.Join('/', f.Path)).Max(name => name.Length);
                foreach (var file in files)
                {
                    var path = string.Join('/', file.Path);
                    Console.WriteLine($"{path.PadRight(maxNameLen + 2)} {Utils.FormatBytesize(file.Length)}");
                }
            }
            Console.WriteLine($"Trackers:\n{string.Join("\n", fileInfo.AnnounceList.Select(t => string.Join(", ", t)))}");
        }
Exemplo n.º 2
0
            protected static async Task <(TorrentFileDto, BEnc)> GetTorrentFileDtoAsync(FileInfo torrent)
            {
                var content = await File.ReadAllBytesAsync(torrent.FullName);

                if (!BEnc.TryParseExpr(content, out var expr, out var read) ||
                    expr == null ||
                    read != content.Length)
                {
                    throw new ArgumentOutOfRangeException(nameof(torrent));
                }

                var dto = MetaInfoSerializer.Deserialize <TorrentFileDto>(expr);

                return(dto, expr);
            }