你好,我正在使用C#在VS15中制作一个控制台应用程序。
如何解码torrent文件?获取torrent文件的名称、大小和日期?我想从服务器上加载一个torrent文件,然后对其进行解码,以查看文件的名称、大小和日期。到目前为止,我可以使用WebCLient下载文件,但我一直在寻找如何解码torrent文件,但没有运气。
我尝试过this library,并这样做:
using (var fs = File.OpenRead("Ubuntu.torrent"))
{
BDictionary bdictionary = Bencode.DecodeDictionary(fs);
}但是我不太明白bdictionary给了我什么?我想在控制台中输出torrents信息。
发布于 2015-09-21 19:19:30
我最近添加了专门用于torrent文件的功能。到目前为止,它是非常基本的,只是为了方便地访问一些信息而具有的属性。
您应该能够像这样提取文件的名称和大小:
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。
https://stackoverflow.com/questions/32067409
复制相似问题