解码(BEncode)种子文件

您好我正在使用C#在VS15中创建一个控制台应用程序。

我怎样才能解码torrent文件? 获取torrent文件的名称,大小和日期? 我想从服务器下载一个torrent文件,然后对其进行解码以查看名称,大小和日期。 到目前为止,我可以使用WebCLient下载文件,但我已经搜索并搜索如何解码torrent文件,但没有运气。

我试过这个库并做了这个:

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

但我不太明白bdictionary给了我什么? 我想在控制台中输出种子信息。

我最近添加了专门用于torrent文件的function。 到目前为止它是非常基本的,只是具有易于访问某些信息的属性。

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

 TorrentFile torrent = Bencode.DecodeTorrentFile("Ubuntu.torrent"); // Calculate info hash (eg "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 。

Interesting Posts