解码(BEncode)种子文件 [英] Decode (BEncode) torrent files

查看:671
本文介绍了解码(BEncode)种子文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用C#在VS15中制作一个控制台应用程序.

Hello I'm making a Console app in VS15 using C#.

如何解码torrent文件?要获得种子文件的名称,大小和日期?我想从服务器上下载一个torrent文件,然后对其进行解码以查看其名称,大小和日期.到目前为止,我可以使用WebCLient下载文件,但是我一直在搜索并搜索如何解码torrent文件,但是没有运气.

How can I decode torrent files? To get the Name, Size and Date of the torrent file? I want to donwload a torrent file from a server and then decode it to see the name, size and date. So far i can download a file using WebCLient, but i have search and search for how to decode a torrent file, but without luck.

我已经尝试过此库,并且执行了以下操作:

I have tried this library and did this:

using (var fs = File.OpenRead("Ubuntu.torrent"))
{
    BDictionary bdictionary = Bencode.DecodeDictionary(fs);
}

但是我不太理解词典给了我什么?我想在控制台中输出种子信息.

But i don't quite understand what bdictionary gives me? I want to output the torrents information in the console.

推荐答案

我最近添加了专门用于种子文件的功能.到目前为止,它是非常基础的,并且具有一些属性,可以轻松访问某些信息.

I have recently added functionality to work specifically with torrent files. So far it is very basic and just have properties for easy access to some of the info.

您应该能够像这样提取文件的名称和大小:

You should be able to extract the name and size of files like this:

TorrentFile torrent = Bencode.DecodeTorrentFile("Ubuntu.torrent");

// Calculate info hash (e.g. "B415C913643E5FF49FE37D304BBB5E6E11AD5101")
string infoHash = torrent.CalculateInfoHash();

// Get name and size of each file in 'files' list of 'info' dictionary ("multi-file mode")
BList files = (BList)torrent.Info["files"];
foreach (BDictionary file in files)
{
    // File size in bytes (BNumber has implicit conversion to int and long)
    int size = (BNumber) file["length"];

    // List of all parts of the file path. 'dir1/dir2/file.ext' => dir1, dir2 and file.ext
    BList path = (BList) file["path"];

    // Last element is the file name
    BString fileName = (BString) path.Last();

    // Converts fileName (BString = bytes) to a string
    string fileNameString = fileName.ToString(Encoding.UTF8);
}

有关存储在.torrent中的数据的更多信息,请查看 BitTorrentSpecification

For more information on the data stored in a .torrent have a look at the BitTorrentSpecification.

这篇关于解码(BEncode)种子文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆