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

时间:2015-12-21 20:56:14

标签: c# torrent magnet-uri monotorrent

有办法吗?我已经尝试过monotorrent,但由于缺乏最新的文档,我不能让它工作。我已经尝试了this monotorrent,但我仍然无法找到获取.torrent文件的方法,甚至无法开始下载以获取.torrent ...

以下代码作为基础that question,但它不会将任何内容保存到“D:\ A”或“D:\ TorrentSave”

#Create the sample file
headers = ['Symbol', 'Price', 'Date', 'Time', 'Change', 'Volume']
rows = [{'Symbol':'AA', 'Price':39.48, 'Date':'6/11/2007',
          'Time':'9:36am', 'Change':-0.18, 'Volume':181800},
        {'Symbol':'AIG', 'Price': 71.38, 'Date':'6/11/2007',
          'Time':'9:36am', 'Change':-0.15, 'Volume': 195500},
        {'Symbol':'AXP', 'Price': 62.58, 'Date':'6/11/2007',
          'Time':'9:36am', 'Change':-0.46, 'Volume': 935000},
        ]

#Open sample file
with open('stocks.csv','w') as f:
    f_csv = csv.DictWriter(f, headers)
    f_csv.writeheader()
    f_csv.writerows(rows)

#Output the dict    
with open('stocks.csv', 'r') as file:
    csvread = csv.DictReader(file, delimiter=',')

    with open('out.csv', 'w') as out:
        headertowrite = ['Time', 'Symbol', 'NewColumn']
        writer = csv.DictWriter(out, headertowrite, extrasaction='ignore')
        writer.writeheader()
        writer.writerows(csvread)
#Works!

要生成.torrent,它不一定是monotorrent,事实上这个api的唯一用途就是那个,从磁链接生成.torrent文件......

编辑:我试图做FᴀʀʜᴀɴAɴᴀᴍ所说的更新代码:

headers = ['Symbol', 'Price', 'Date', 'Time', 'Change', 'Volume']
rows = [{'Symbol':'AA', 'Price':39.48, 'Date':'6/11/2007',
          'Time':'9:36am', 'Change':-0.18, 'Volume':181800},
        {'Symbol':'AIG', 'Price': 71.38, 'Date':'6/11/2007',
          'Time':'9:36am', 'Change':-0.15, 'Volume': 195500},
        {'Symbol':'AXP', 'Price': 62.58, 'Date':'6/11/2007',
          'Time':'9:36am', 'Change':-0.46, 'Volume': 935000},
        ]

with open('stocks.csv','w') as f:
    f_csv = csv.DictWriter(f, headers)
    f_csv.writeheader()
    f_csv.writerows(rows)

with open('stocks.csv', 'r') as file:
    csvread = csv.DictReader(file, delimiter=',')


    for row in csvread:
        row['NewColumn'] = '1'

    with open('out.csv', 'w') as out:
        headertowrite = ['Time', 'Symbol', 'NewColumn']
        writer = csv.DictWriter(out, headertowrite, extrasaction='ignore')
        writer.writeheader()
        writer.writerows(csvread)
#Out.csv is blank!

Hash used =“5FC86BA08451CF4221E0091F31AF1A52C2219009”

1 个答案:

答案 0 :(得分:-1)

您只需将哈希值而不是整个磁力​​链接传递给TorrentManager构造函数。

磁力链接如下所示:

magnet:?xt=urn:btih:18981bc9759950b4715ad46adcaf514e6a773cfe

所以,更通用的形式:

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

您需要提取此<hash>并将其传递给构造函数:

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