public void TestAddAndRemoveTorrent()
        {
            try
            {
                UTorrentClient client = new UTorrentClient("admin", "password");
                using (System.IO.FileStream file = System.IO.File.OpenRead("dummy.torrent"))
                {
                    var addResponse = client.PostTorrent(file);
                    Assert.IsNotNull(addResponse);
                    Assert.IsNotNull(addResponse.Result);
                    Assert.IsNull(addResponse.Result.Error);
                    Assert.IsNotNull(addResponse.AddedTorrent);
                    Torrent torrent = addResponse.AddedTorrent;

                    var deleteResponse = client.DeleteTorrent(torrent.Hash);
                    Assert.IsNotNull(deleteResponse);
                    Assert.IsNotNull(deleteResponse.Result);
                    Assert.IsNull(deleteResponse.Result.Error);
                }
            }
            catch (ServerUnavailableException)
            {
                Assert.Inconclusive("Serveur unavailable");
            }
            catch (InvalidCredentialException)
            {
                Assert.Inconclusive("Invalid credential");
            }
        }
예제 #2
0
        public void TestAddAndRemoveTorrent()
        {
            try
            {
                UTorrentClient client = new UTorrentClient("admin", "password");
                using (System.IO.FileStream file = System.IO.File.OpenRead("dummy.torrent"))
                {
                    var addResponse = client.PostTorrent(file);
                    Assert.IsNotNull(addResponse);
                    Assert.IsNotNull(addResponse.Result);
                    Assert.IsNull(addResponse.Result.Error);
                    Assert.IsNotNull(addResponse.AddedTorrent);
                    Torrent torrent = addResponse.AddedTorrent;

                    var deleteResponse = client.DeleteTorrent(torrent.Hash);
                    Assert.IsNotNull(deleteResponse);
                    Assert.IsNotNull(deleteResponse.Result);
                    Assert.IsNull(deleteResponse.Result.Error);
                }
            }
            catch (ServerUnavailableException)
            {
                Assert.Inconclusive("Serveur unavailable");
            }
            catch (InvalidCredentialException)
            {
                Assert.Inconclusive("Invalid credential");
            }
        }
        public void TestAddAndRemoveTorrent()
        {
            try
            {
                var dummyFile =
                    "ZDEwOmNyZWF0ZWQgYnkx" +
                    "Mzp1VG9ycmVudC8zMzAw" +
                    "MTM6Y3JlYXRpb24gZGF0" +
                    "ZWkxMzc1NTU5MjcyZTg6" +
                    "ZW5jb2Rpbmc1OlVURi04" +
                    "NDppbmZvZDY6bGVuZ3Ro" +
                    "aTVlNDpuYW1lOTpkdW1t" +
                    "eS50eHQxMjpwaWVjZSBs" +
                    "ZW5ndGhpMTYzODRlNjpw" +
                    "aWVjZXMyMDqCnDgEQBsH" +
                    "J/cPc9RBXhYkAMvlezc6" +
                    "cHJpdmF0ZWkxZWVl";

                var            bytes  = Convert.FromBase64String(dummyFile);
                UTorrentClient client = new UTorrentClient("admin", "password");
                using (var file = new MemoryStream(bytes))
                {
                    var addResponse = client.PostTorrent(file);
                    Assert.IsNotNull(addResponse);
                    Assert.IsNotNull(addResponse.Result);
                    Assert.IsNull(addResponse.Result.Error);
                    Assert.IsNotNull(addResponse.AddedTorrent);
                    Torrent torrent = addResponse.AddedTorrent;

                    var deleteResponse = client.DeleteTorrent(torrent.Hash);
                    Assert.IsNotNull(deleteResponse);
                    Assert.IsNotNull(deleteResponse.Result);
                    Assert.IsNull(deleteResponse.Result.Error);
                }
            }
            catch (AggregateException ex)
            {
                if (ex.InnerException is ServerUnavailableException || ex.InnerException is InvalidCredentialException)
                {
                    Assert.Inconclusive("Serveur unavailable");
                }
                throw;
            }
            catch (ServerUnavailableException)
            {
                Assert.Inconclusive("Serveur unavailable");
            }
            catch (InvalidCredentialException)
            {
                Assert.Inconclusive("Invalid credential");
            }
        }
예제 #4
0
        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);
        }