简体   繁体   English

使用C#将Torrent Magnet链接转换为.torrent文件

[英]Convert Torrent Magnet link to a .torrent file with c#

Is there a way to do it? 有办法吗? I already tried with monotorrent, but due to the lack of up-to-date documentation i coudn't get it to work. 我已经尝试过monotorrent,但是由于缺少最新文档,我无法使其正常工作。 I've already tried this with monotorrent, but still i can't find a way to get the .torrent file or even start the download to get the .torrent ... 我已经用monotorrent尝试过方法,但是我仍然找不到找到.torrent文件的方法,甚至无法开始下载以获得.torrent的方法...

The following piece of code was made that question as base, but it doesn't save anything to "D:\\A" or to "D:\\TorrentSave" 以下代码段使该问题作为基础,但并未将任何内容保存到“ D:\\ A”或“ D:\\ TorrentSave”

    private void GerarTorrent(string magnet)
    {
        MonoTorrent.Client.TorrentManager b = new MonoTorrent.Client.TorrentManager(new MonoTorrent.MagnetLink(magnet), "D:\\A", new MonoTorrent.Client.TorrentSettings(), "D:\\TorrentSave");
        MonoTorrent.Client.EngineSettings engineSettings = new MonoTorrent.Client.EngineSettings();
        MonoTorrent.Client.ClientEngine clientEngine = new MonoTorrent.Client.ClientEngine(engineSettings);
        clientEngine.Register(b);
        clientEngine.StartAll();
        b.Start();
    }

To generate the .torrent, it doesn't have to be monotorrent, in fact the only usage of this api would be for that, generating .torrent files from a magnet link... 生成.torrent的过程不必一定是monotorrent,实际上,此api的唯一用途就是从磁力链接生成.torrent文件...

EDIT: Updated code with my attempt on doing what Fᴀʀʜᴀɴ Aɴᴀᴍ said: 编辑:我尝试做FᴀʀʜᴀɴAɴᴀᴍ所说的更新了代码:

    private void GerarTorrent(string hash)
    {
        MonoTorrent.Client.TorrentManager b = new MonoTorrent.Client.TorrentManager(MonoTorrent.InfoHash.FromHex(hash), "D:\\A", new MonoTorrent.Client.TorrentSettings(), "D:\\TorrentSave", new List<List<string>>());
        MonoTorrent.Client.EngineSettings engineSettings = new MonoTorrent.Client.EngineSettings();
        MonoTorrent.Client.ClientEngine clientEngine = new MonoTorrent.Client.ClientEngine(engineSettings);
        clientEngine.Register(b);
        clientEngine.StartAll();
        b.Start();
    }

Hash used = "5FC86BA08451CF4221E0091F31AF1A52C2219009" 使用的哈希=“ 5FC86BA08451CF4221E0091F31AF1A52C2219009”

You need to pass only the hash and not the entire magnet link to the TorrentManager constructor. 您只需要将散列而不是整个磁铁链接传递给TorrentManager构造函数。

A magnet link looks like this: 磁链看起来像这样:

magnet:?xt=urn:btih:18981bc9759950b4715ad46adcaf514e6a773cfe

So, a more generalized form: 因此,一种更通用的形式:

magnet:?xt=urn:btih:<hash>

You need to extract this <hash> and pass it to the constructor: 您需要提取此<hash>并将其传递给构造函数:

manager = new TorrentManager(InfoHash.FromHex(hash), downloadsPath, torrentDefaults, downloadsPathForTorrent, new List<List<string>>());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM