private static void GetTorrentFileList(IList <Model.TorrentFileName> filelist, BDictionary file) { // File size in bytes (BNumber has implicit conversion to int and long) long 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"]; string fullpath = String.Join("\\", 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); var tf = new Model.TorrentFileName(); tf.Name = fileNameString; tf.Size = size; tf.Path = fullpath; tf.IsWanted = true; filelist.Add(tf); }
public void ReadLocalTorrentFile() { bool isMultiFile; //string file = @"C:\Users\dan.PARADOX\Downloads\ubuntu-14.10-desktop-amd64.iso.torrent"; string localfile = @"C:\Users\dan.PARADOX\Downloads\[kat.cr]deadpool.2016.1080p.bluray.x264.dts.jyk.torrent"; TorrentFile torrent = Bencode.DecodeTorrentFile(localfile); List <string> filelist = new List <string>(); if (torrent.Info.ContainsKey("files")) { BList files = (BList)torrent.Info["files"]; foreach (BDictionary file in files) { //http://stackoverflow.com/questions/32067409/decode-bencode-torrent-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"]; string fullpath = String.Join("|", 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); } } else { filelist.Add(torrent.Info["name"].ToString()); } }