public void TestGetTorrentWithFiles() { try { UTorrentClient client = new UTorrentClient("admin", "password"); var response = client.GetList(); Assert.IsNull(response.Error); Assert.IsNotNull(response.Result); Assert.IsNotNull(response.Result.Torrents); Assert.AreNotEqual(response.Result.Torrents.Count, 0); var torrent = response.Result.Torrents[0]; response = client.GetTorrent(torrent.Hash.ToLower()); Assert.IsNull(response.Error); Assert.IsNotNull(response.Result); torrent = UTorrentClient.ConsolidateTorrent(response, torrent.Hash); Assert.IsNotNull(torrent); Assert.IsNotNull(torrent.Files); Assert.AreNotEqual(torrent.Files.Count, 0); } catch (ServerUnavailableException) { Assert.Inconclusive("Serveur unavailable"); } catch (InvalidCredentialException) { Assert.Inconclusive("Invalid credential"); } }
static void Main(string[] args) { _uTorrentClient = new UTorrentClient(Config.UTorrent.Ip, Config.UTorrent.Port, Config.UTorrent.Username, Config.UTorrent.Password); if (args.Length != 1) { Log.Error("Only Torrent hash id is expected as an argument"); Environment.Exit(-1); } try { var torrents = _uTorrentClient.GetList(); if (torrents.Error != null) { Log.Error(torrents.Error.Message); Environment.Exit(-1); } var torrent = torrents.Result.Torrents.SingleOrDefault(x => x.Hash == args[0]); if (torrent == null) { Log.ErrorFormat("Torrent with hash {0}, was not found", args[0]); Environment.Exit(-1); } switch (torrent.Label) { case "tv": CopyTorrentToFolder(torrent.Path, torrent.Hash, Config.UTorrent.TvDownloadFolder); if (Config.UTorrent.TorrentRatio == 0 || torrent.Ratio >= Config.UTorrent.TorrentRatio * 100) { _uTorrentClient.DeleteTorrent(torrent.Hash); } break; case "movies": CopyTorrentToFolder(torrent.Path, torrent.Hash, Config.UTorrent.MoviesDownloadFolder); if (Config.UTorrent.TorrentRatio == 0 || torrent.Ratio >= Config.UTorrent.TorrentRatio * 100) { _uTorrentClient.DeleteTorrent(torrent.Hash); } break; } } catch (ServerUnavailableException) { Log.Error("The utorrent server cannot be reach"); Environment.Exit(-1); } Environment.Exit(0); }
public void TestGetAllTorrent() { try { UTorrentClient client = new UTorrentClient("admin", "password"); var response = client.GetList(); Assert.IsNull(response.Error); Assert.IsNotNull(response.Result); Assert.IsNotNull(response.Result.Torrents); } catch (ServerUnavailableException) { Assert.Inconclusive("Serveur unavailable"); } catch (InvalidCredentialException) { Assert.Inconclusive("Invalid credential"); } }