1

У меня есть хэш торрента (MD5). Вопрос в том, как с помощью MonoTorrent скачать торрент-файл. Это можно сделать с помощью метода из uTorrent API. В смысле не совсем это, потому что он не умеет просто скачивать торрент-файл, он начинает загрузку содержимого. Мне же нужен только список содержимого.

Почти снимает вопрос эта строчка "http://"+"torcache.net/torrent/" Если прибавить к ней с конца строчку вида "[ХЭШ].torrent" и перейти по этой ссылке в браузере, то скачивается нужный файл. Но если сделать то же с помощью

using (WebClient wc = new WebClient()) {
wc.DownloadFile("http://"+"torcache.net/torrent/[HASH].torrent", @"[PATH]");
}

то тоже скачивается *.torrent, но почему-то не закодированный. uTorrent его не может прочитать, выдаёт ошибку "Torrent Is Not Valid Bencoding".

Всё должно работать примерно так и files должен содержать то, что нужно

ClientEngine engine;
EngineSettings settings = new EngineSettings();

string hash = @"163B5E7C7D22B57E26DCC6DA5951104453769E61";
string magnet = string.Format("magnet:?xt=urn:btih:{0}", hash);
MagnetLink ml = new MagnetLink(magnet);
TorrentManager manager = new TorrentManager(ml1,
                [ПУТЬ СОХРАНЕНИЯ],
                new TorrentSettings(),
                [ПУТЬ К ТОРРЕНТУ]);
engine.Register(manager);
manager.Start();

List<TorrentFile> files = manager.Torrent.Files.ToList();

Однако files оказывается пуст. Вероятно, не работает конструктор MagnetLink.

1 ответ 1

0

Решение найдено благодаря ошибке uTorrent.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using fh = FileHelpers;
using UTorrent.Api;
using UT = UTorrent;
using MonoTorrent.Client;
using MonoTorrent.Client.Encryption;
using MonoTorrent.Common;

namespace csvTorrent {
class Program {
    private static string path1 = @"A:\torrents\category_8";
    static void Main(string[] args) {
        var engine = new fh.FileHelperEngine<MyTorrents>();
        var res = engine.ReadFile(path1 + ".csv");
        string magHead = @"magnet:?xt=urn:btih:";
        int k = 0;
        for (int i = 0; i < res.Length; i++) {
            UT.Api.UTorrentClient UTC = new UTorrentClient("admin", "admin");
            UTC.AddUrlTorrent(magHead + res[i]._hash, @"c:\torrents");
            UTC.RecheckTorrent(magHead + res[i]._hash);
            k++;
            if (k == 20) {
                Console.ReadLine();
                k = 0;
            }
        }

        string torrentsPath = @"C:\torrents";

        ClientEngine monoEngine;

        EngineSettings settings = new EngineSettings();
        settings.AllowedEncryption = EncryptionTypes.All;
        settings.SavePath = Path.Combine(Environment.CurrentDirectory, "torrents");

        if (!Directory.Exists(settings.SavePath))
            Directory.CreateDirectory(settings.SavePath);

        monoEngine = new ClientEngine(settings);
        monoEngine.Settings.SavePath = @"C:\torrents";

        List<string> _torrents = new List<string>();
        _torrents = Directory.EnumerateFiles(torrentsPath).ToList();
        foreach (string s in _torrents) {
            Torrent torrent = Torrent.Load(s);
            TorrentManager manager = new TorrentManager(torrent,
            @"C:\torrents",
            new TorrentSettings(),
            @"C:\torrents");

            monoEngine.Register(manager);

            manager.Start();

            List<TorrentFile> files = manager.Torrent.Files.ToList();
            using (TextWriter sw = File.AppendText(@"A:\torrents\hashes.txt")) {
                foreach (TorrentFile file in files) {
                    sw.WriteLine(file.Path);
                }
            }
        }
    }
}
//"ForumId форума";"Название форума";"ForumId раздачи";"Info hash";"Название раздачи";"Размер в байтах","Дата регистрации торрента"
[fh.DelimitedRecordAttribute(";")]
class MyTorrents {
    public string _forumId;
    public string _forumName;
    public string _torrentId;
    public string _hash;
    public string _torrentName;
    public string _size;
    public string date;
}
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.